1、split方式

<html>

<head></head>

<body onload="convertTemp()">

<script language="javaScript">

function convertTemp()

{

   var the_url = prompt("What's the URL?","");

var first_split = the_url.split("//");

alert(first_split[0]);

  

   var without_resource = first_split[1];

var second_split = without_resource.split("/");

var domain = second_split[0];

  

   alert(domain);

}

</script>

</body>

</html>

2、substring方式

<html>

<head></head>

<body onload="convertTemp()">

<script language="javaScript">

function convertTemp()

{

   var the_url = prompt("What's the URL?","");

var lead_slashes = the_url.indexOf("//");

var domain_start = lead_slashes + 2;

var without_resource = the_url.substring(domain_start, the_url.length);

var next_slash = without_resource.indexOf("/");

var domain = without_resource.substring(0, next_slash);

  

   alert(domain);

}

</script>

</body>

</html>

执行效果图:

最新文章

  1. SpringMVC访问静态资源的三种方式(转)
  2. ofbiz进击 个人遇到的奇葩问题汇总。
  3. 淮安团购网美团联盟网赚版 v5.7
  4. mysql中bigint在php中表示
  5. chrome调试ajax
  6. USACO 3.3 A Game
  7. CSS用足够大的纯色内阴影去覆盖掉谷歌input记住账号或密码时默认出现的黄色背景
  8. (java web后端方向)如何让你的简历为你争取到更多的面试机会,内容来自java web轻量级开发面试教程
  9. 转:Flutter动画二
  10. Devexpress GridControl 多选
  11. java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例
  12. TCP/IP笔记(1)
  13. 函数和常用模块【day05】:迭代器(六)
  14. Angular4 Ng 模块
  15. 帝国cms建站总结-(分页)
  16. 使用pymongo连接mongodb时报错:pymongo.errors.OperationFailure: not authorized
  17. ZooKeeper参数调优
  18. 【转】SQL SERVER 中 sp_rename 用法
  19. Eclipse 调试总进入Spring代理的解决办法
  20. 551. Student Attendance Record I + Student Attendance Record II

热门文章

  1. Windows Phone 8初学者开发—第20部分:录制Wav音频文件
  2. hdu4722之简单数位dp
  3. Android 富文本框实现 RichEditText
  4. Mysql zip 安装(windows)
  5. css图片上下垂直居中
  6. Netty源代码学习——ChannelPipeline模型分析
  7. Java byte数据类型详解
  8. 初入Android--Activate生命周期
  9. JDK 环境变量配置(Mac)
  10. WM_DRAWITEM与DrawItem()的讨论(自绘)