我尝试在jquery中创建一个函数,该函数将域名分开。

即,如果域名=“ google.co.in”或“ google.com”,则应分隔域名,并在jquery中将两个变量存储为域名=“ google”和TLD =“ co.in”。
我对此进行了一些尝试,这是我的fiddle,这是我的代码

<p id="demo">Click the button to display the array values after the split.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var str = "www.google.co.in";
var res = str.split(".",1);
document.getElementById("demo").innerHTML=res;
}
</script>

最佳答案

尝试这样:

var res = str.split(".")[1];
var rest = str.split(".")[2] + "." + str.split(".")[3];

10-01 20:52
查看更多