想知道如何使用location.href传递参数/值 [英] would like to know how to pass parameter/value using location.href
本文介绍了想知道如何使用location.href传递参数/值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想知道如何使用location.href传递参数/值
这是我的代码请求说是正确还是没有
< script >
function btnExternalPayGhest_Click(id){
if(id == 190){
document.location.href =frmInstallmentPayment.aspx+ GhestCompanyID,ExternalGhestID,ExternalCellPhone;
}
else if(id == 240){
document.location.href =frmInstallmentPayment.aspx+ GhestCompanyID,ExternalGhestID, ExternalCellPhone;
}
}
< / script >
< 表格 名称 = form1 >
< 输入 类型 = 按钮 name = بررسی value = بررسی onclick =' btnExternalPayGhest_Click()' >
< / form < span class =code-keyword>>
解决方案
您的代码没有太大的逻辑意义,但基本上你可以用以下参数设置一个URL:
location .href = ' page.aspx?x =' + param1 + ' & y =' + param2 + ' & z =' + param3;
href是一个字符串,可以包含一个URL地址,其中包含一些查询字符串格式的参数...
par1 = val1& par2 = val2
如果您有值,可以使用 jQuery的param [ ^ ]方法从JavaScript对象创建此类字符串很容易......
var params = {
param1:GhestCompanyID,
param2的:ExternalGhestID,
param3:ExternalCellPhone
}
document 。 location .href = frmInstallmentPayment.aspx? +
.param(params);
hi
I would like to know how to pass parameter/value using location.href
this is my code pleas say is correct or no
<script >
function btnExternalPayGhest_Click(id) {
if (id == 190) {
document.location.href = "frmInstallmentPayment.aspx" + GhestCompanyID, ExternalGhestID, ExternalCellPhone;
}
else if (id == 240) {
document.location.href = "frmInstallmentPayment.aspx" + GhestCompanyID, ExternalGhestID, ExternalCellPhone;
}
}
</script>
<form name="form1">
<input type="button" name="بررسی" value="بررسی" onclick='btnExternalPayGhest_Click()'>
</form>
解决方案
Your code doesn't make a lot of logical sense, but essentially you can set a URL with paramters like:
location.href = 'page.aspx?x=' + param1 + '&y=' + param2 + '&z=' + param3;
If you need to pass nonalphanumeric characters you may neeed to look into encoding [^] it.
href is a string that can contain an URL address wit some parameters in the format of query string...
par1=val1&par2=val2
If you have the values you can use jQuery's param[^] method to create such string from a JavaScript object easily...
var params = { "param1": GhestCompanyID, "param2": ExternalGhestID, "param3": ExternalCellPhone } document.location.href = "frmInstallmentPayment.aspx?" +
.param( params );
这篇关于想知道如何使用location.href传递参数/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文