js中substring或split方法取得URL中的域名
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>
執行效果圖:
相關推薦
js中substring或split方法取得URL中的域名
1、split方式 <html> <head></head> <body onload="convertTemp()"> <script language="javaScript"> function conver
java java中subString、split、stringTokenizer三種擷取字串方法的效能比較
面試的時候,string 基本上是必須問的知識 突然想起面試的時候曾經被人問過:都知道在大資料量情況下,使用String的split擷取字串效率很低,有想過用其他的方法替代嗎?用什麼替代?我當時的回答很斬釘截鐵:沒有。 google了一下,發現有2中替代方法,於
js中substring()與substr()方法的區別
在js中substring()與substr(),這兩個函式都存在,並且最後那個字母“s”都是小寫。 兩個功能差不多,但是有區別: 1.與 slice() 和 substr() 方法不同的是,substring() 不接受負的引數。 2.substr(index
Java中substring、split、StringTokenizer三種擷取字串方法的效能比較
最近在閱讀java.lang下的原始碼,讀到String時,突然想起面試的時候曾經被人問過:都知道在大資料量情況下,使用String的split擷取字串效率很低,有想過用其他的方法替代嗎?用什麼替代?我當時的回答很斬釘截鐵:沒有。 Google了一下,發現有2種替代方法,於是
在頁面跳轉的時候,在跳轉後的頁面中使用js 獲取到 頁面跳轉的url中攜帶的引數。
common.js程式碼 //獲取URL中的引數..等等function getQueryString(name){ var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)"); var r = window.location.
jquery中html()或text()方法獲取或設定p標籤的值
設定內容 - text()、html() 以及 val() 我們將使用前一章中的三個相同的方法來設定內容: text() - 設定或返回所選元素的文字內容html() - 設定或返回所選元素的內容(包括 HTML 標記)val() - 設定或返回表單欄位的值
通過getChildAt方法取得AdapterView中第n個Item(重新編輯)
以前對於AdapterView(ListView和GridView的父類)以及這個類的getChildAt()方法理解十分粗淺,以為是指傳入一個絕對position(就是這個item是AdapterView第幾個元素)來直接獲得到該item,當然,android
Mysql中的字串拆分方法 (類似java中split()與PaAdmin庫中的split_part()函式)
【原理】://fSELECT SUBSTRING_INDEX('a,b,c,d,e,f',',',-1) ; -- f != 'a,b,c,d,e,f'//eSELECT SUBSTRING_INDEX('a,b,c,d,e,f',',',-2) ; -- e,f !=
split()方法分割字串中的問題
使用split()方法可以是字串按指定的分割字元或字串對內容進行分割,並將分割後的結果存放在字串陣列中。split()方法提供了以下兩種過載形式: (1)split(String sign) 該方法可根據給定的分割符對字串進行拆分。 語法如下: st
URL中“#” “?” &“”號的作用 URL中“#” “?” &“”號的作用
URL中“#” “?” &“”號的作用 閱讀目錄 1. # 2. ? 3. & 回到頂部 1. # 10年9月,t
關於idea建立struts2中web.xml的filter的url中struts無法解析的問題
新建完成之後,我們可以看到只有六個基礎包,網上看視訊的時候發現引入的包很多,開始以為是沒有引入相應的包,的確,看報名確實沒有,但是這個相應的包是包含在struts2-core.jar裡面的。不是引入包的問題。那就是路徑問題了。我們看相應的路徑的時候,發現沒有ng這個目錄。 但是在xml中石油這
java取得URL頂級域名
String url = "http://anotherbug.blog.chinajavaworld.com/entry/4545/0/"; Pattern p = Pattern.compile("(?<=http://|\\.)[^.]*?\\.(com|cn|
使用JS獲取URL中參數的方法
彈出 port there href 字串 span window subst var 1、獲取整個URL字符串 要想獲取URL中的參數,首先我們就要獲取到整個URL字符串。我們以http://localhost:8080/Charge/homePage.html?cost
JS獲取URL中引數值的4種方法
方法一:正則法 function getQueryString(name) {var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');var r = window.location.se
js中獲取url中引數的方法
JS中獲取url中引數的方法(帶中文的也可以): function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r =
案例:JS獲取URL中引數值的方法
假設位址列地址是:http://localhost:3000/m/productlist.html?search=%E9%9E%8B 思路分析: 1.location.search//得到?search=%E9%9E%8B 2.location.search.substring(1)//"s
js方法實現獲取url中的參數值
geturl log regex ram block search 獲取url 說明 urn 實現方法如下: /** * @param name:指的是url中的參數名 */ function getUrlParam(name) { var reg = new Re
父視窗和iframe子視窗之間相互傳遞引數和呼叫函式或方法(url中傳參)
1.父視窗向子視窗傳遞引數: 可以在url中新增引數:2.html?a=1&b=2&c=3 然後在子頁面上可用js解析,提供一個函式: function getQueryStr(sArgName)
js獲取頁面url中的各項值
js一、 通過window.location獲取各項參數1、獲取頁面完整的urlurl = window.location.href;2、獲取頁面的域名host = window.location.host;host2=document.domain; 應用場景:頁面跳轉,開發環境和測試環境域名不同,所以需要
spring mvc中關於url中傳遞中文亂碼的解決方法
般的 har rac color nco bytes utf8 int span 在傳值過程中,也是亂碼出現的頻繁地。先不說到底是什麽場景了,通常常用的方案有如下幾個 配置指定的filter <!-- 配置請求過濾器,編碼格式設為UTF-8,避免中文亂碼-->