一天一個js(2)網址截取

來源:互聯網
上載者:User

[html] 
<!DOCTYPE HTML> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(function(){ 
    $(".btn").click(function(){ 
        var p4 = $(".text").val(); 
        var rule2 = /(\w+):\/\/(\w+\.?\w+\.\w+)(:?\d*)(\/(\w|\W)+)/; 
        var re2 = p4.replace(rule2,""); 
        var xy = RegExp.$1; 
        var dz = RegExp.$2; 
        var hz = RegExp.$4; 
        $("span").append("協議是:"+xy+"<br />網址是:"+dz+"<br />尾碼是:"+hz); 
    }); 
}); 
</script> 
<style type="text/css"> 
div { width:400px; padding:10px; border:1px solid #000; margin:200px auto;} 
.text { width:400px; height:300px; resize:none;} 
.btn { width:100px; height:20px; margin:20px 0 0;} 
</style> 
<title>網址截取</title> 
</head> 
 
<body> 
<div> 
    <textarea class="text">http://www.ifblooms.com/thread-4479-1-1.html</textarea> 
    <p>輸入網址,分解為協議、網域名稱地址以及頁面路徑</p> 
    <input class="btn" value="擷取" type="button" /><br /> 
    <span></span> 
</div> 
</body> 
</html> 

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
 $(".btn").click(function(){
  var p4 = $(".text").val();
  var rule2 = /(\w+):\/\/(\w+\.?\w+\.\w+)(:?\d*)(\/(\w|\W)+)/;
  var re2 = p4.replace(rule2,"");
  var xy = RegExp.$1;
  var dz = RegExp.$2;
  var hz = RegExp.$4;
  $("span").append("協議是:"+xy+"<br />網址是:"+dz+"<br />尾碼是:"+hz);
 });
});
</script>
<style type="text/css">
div { width:400px; padding:10px; border:1px solid #000; margin:200px auto;}
.text { width:400px; height:300px; resize:none;}
.btn { width:100px; height:20px; margin:20px 0 0;}
</style>
<title>網址截取</title>
</head>

<body>
<div>
 <textarea class="text">http://www.ifblooms.com/thread-4479-1-1.html</textarea>
 <p>輸入網址,分解為協議、網域名稱地址以及頁面路徑</p>
 <input class="btn" value="擷取" type="button" /><br />
 <span></span>
</div>
</body>
</html>


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.