如何在 java 脚本的超链接中传递多个参数?
How to pass multiple argument in a hyperlink in java scriipt?
我正在尝试使用 JavaScript 创建动态 hyperlink。我正在使用“&”传递多个参数,但我遇到了解析错误。
JavaScript:
<script>
function visitPage() {
var phn = document.getElementById("bid").value;
var totalprice = spans[3].innerHTML;
window.location.href = 'https://www.instamojo.com/stayuncle/payments-for-stayuncle?data_amount='
+ totalprice + '&' + 'data_Field_68092=' + phn;
}
</script>
错误:
The entity name must immediately follow the '&' in the entity reference.
我试图通过传递 '&'
来修复它,结果 link 看起来像这样:
https://www.instamojo.com/stayuncle/payments-for-stayuncle/?data_amount=1374.75&data_Field_68092=Hotel%20Delhi%20Airport%20Link
'&' 仍在 link 中,而不是自己转换为 & 符号。
我还删除了每个 &
后的分号 (;
),因为它没有让我 post 实际问题。
var a = 1374.75;
var b = 'Hotel Delhi Airport Link';
var url = 'https://www.instamojo.com/stayuncle/payments-for-stayuncle'
var link = decodeURIComponent(url+'?data_amount='+a+'&data_Field_68092='+b)
alert("Redirecting to"+ link)
location.href = link
还需要将代码包装在 <![CDATA[ code //]]>
中,因为使用 Thymeleaf。
var totalprice = 1374.75;
var name = 'Hotel Delhi Airport Link';
var email='n@gmail.com';
var phn='1111111111'
var link = decodeURIComponent('http://www.example.com?data_amount='+totalprice+'&'+'data_name='+name+'&'+'data_email='+email+'&'+'data_phn='+phn)
alert("Redirecting to"+ link)
location.href = link
var x = 1374.75;
var y = 'Tesxt Data';
var link = decodeURIComponent('URL='+x+'With Field='+y)
alert("Redirecting to"+ link)
location.href = link
因为我使用 Thymeleaf 作为前端,而 Thymeleaf 使用 XML underlying.so 在这种情况下需要 CDATA 部分。这是对我有用的代码快照。有关更多详细信息,请参阅本节
When is a CDATA section necessary within a script tag?
// <![CDATA[
var a = 1374.75;
var b = 'Hotel Delhi Airport Link';
var link = decodeURIComponent('https://www.instamojo.com/stayuncle/payments-for-stayuncle?data_amount='+a+'&data_Field_68092='+b)
alert("Redirecting to"+ link)
location.href = link
//]]>
在使用 XML 添加//作为 Thymeleaf 为我工作后,要实现 & 和其他特殊符号需要添加“
我正在尝试使用 JavaScript 创建动态 hyperlink。我正在使用“&”传递多个参数,但我遇到了解析错误。
JavaScript:
<script>
function visitPage() {
var phn = document.getElementById("bid").value;
var totalprice = spans[3].innerHTML;
window.location.href = 'https://www.instamojo.com/stayuncle/payments-for-stayuncle?data_amount='
+ totalprice + '&' + 'data_Field_68092=' + phn;
}
</script>
错误:
The entity name must immediately follow the '&' in the entity reference.
我试图通过传递 '&'
来修复它,结果 link 看起来像这样:
https://www.instamojo.com/stayuncle/payments-for-stayuncle/?data_amount=1374.75&data_Field_68092=Hotel%20Delhi%20Airport%20Link
'&' 仍在 link 中,而不是自己转换为 & 符号。
我还删除了每个 &
后的分号 (;
),因为它没有让我 post 实际问题。
var a = 1374.75;
var b = 'Hotel Delhi Airport Link';
var url = 'https://www.instamojo.com/stayuncle/payments-for-stayuncle'
var link = decodeURIComponent(url+'?data_amount='+a+'&data_Field_68092='+b)
alert("Redirecting to"+ link)
location.href = link
还需要将代码包装在 <![CDATA[ code //]]>
中,因为使用 Thymeleaf。
var totalprice = 1374.75;
var name = 'Hotel Delhi Airport Link';
var email='n@gmail.com';
var phn='1111111111'
var link = decodeURIComponent('http://www.example.com?data_amount='+totalprice+'&'+'data_name='+name+'&'+'data_email='+email+'&'+'data_phn='+phn)
alert("Redirecting to"+ link)
location.href = link
var x = 1374.75;
var y = 'Tesxt Data';
var link = decodeURIComponent('URL='+x+'With Field='+y)
alert("Redirecting to"+ link)
location.href = link
因为我使用 Thymeleaf 作为前端,而 Thymeleaf 使用 XML underlying.so 在这种情况下需要 CDATA 部分。这是对我有用的代码快照。有关更多详细信息,请参阅本节 When is a CDATA section necessary within a script tag?
// <![CDATA[
var a = 1374.75;
var b = 'Hotel Delhi Airport Link';
var link = decodeURIComponent('https://www.instamojo.com/stayuncle/payments-for-stayuncle?data_amount='+a+'&data_Field_68092='+b)
alert("Redirecting to"+ link)
location.href = link
//]]>