<script>
var url = window.location.href;
</script>
获取到当前网址,假设网址是http://www.asiafxsol.com/register/demoAccountOk.aspx?PromotionCode=1521160&InitialAccountBalance=50000&U=u1632270&P=u1632270
我想把最后的u1632270和u1632270 截取出来 该怎么写代码啊?
新手学习,谢谢大家帮助!
var url = window.location.href;
</script>
获取到当前网址,假设网址是http://www.asiafxsol.com/register/demoAccountOk.aspx?PromotionCode=1521160&InitialAccountBalance=50000&U=u1632270&P=u1632270
我想把最后的u1632270和u1632270 截取出来 该怎么写代码啊?
新手学习,谢谢大家帮助!
而是用服务端代码读出
比如asp.net可以这样var U='<%=Request.QueryString("U")%>';
var P='<%=Request.QueryString("P")%>';
cod=document.getElementById(cod1)
var code=cod.value;
if (code!=""){
var newwin=window.open('','','');
newwin.opener = null
newwin.document.write(code);
newwin.document.close();
}
}
//复制代码
function doCopy2(ID) {
if (document.all){
textRange = document.getElementById(ID).createTextRange();
textRange.execCommand("Copy");
alert('复制成功');
}
else{
alert("此功能只能在IE上有效")
}
}
//复制代码
function doCopy(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}function doCopyUrl()
{
document.getElementById("CopyUrl").value=parent.location.href;
document.getElementById("CopyUrl").select();
document.execCommand("copy");
alert("网址成功复制到剪贴板!")
} //另存代码
function doSave(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
//var url = window.location.href;
var url="http://www.asiafxsol.com/register/demoAccountOk.aspx?PromotionCode=1521160&InitialAccountBalance=50000&U=u1632270&P=u1632270"
ut= url.split("&U=")[1].split("&P=")
u=ut[0]
p=ut[1]
alert(u+"\n"+p)
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> URL </title>
<meta name="author" content="xxd851116" />
</head>
<body>
<script type="text/javascript">
function URL(url) {
url = url || "http://blog.csdn.net/xxd851116";
this.url = url.toString() ;
}URL.prototype.getValue = function(key) {
if (this.url == null) return;
if (key == null) return;
var key_values = this.url.split("?")[1].split("&");
for (var i = 0; i < key_values.length ; i++ )
{
var key_value = key_values[i].split("=");
if (key == key_value[0])
{
return key_value[1];
}
}
}var url = "http://www.asiafxsol.com/register/demoAccountOk.aspx?PromotionCode=1521160&InitialAccountBalance=50000&U=u1632270&P=u1632270" ;
var url = new URL(url);
document.writeln("U = " + url.getValue("U") + ";<br/>");
document.writeln("P = " + url.getValue("P") + ";<br/>");
</script>
</body>
</html>测试输出结果:U = u1632270;
P = u1632270;