[英]how to pass variable from DOM script to href link
I want to pass a variable from java script to html link.我想将一个变量从 java 脚本传递到 html 链接。
<li hidden><a id="url_call" href='/paytm/response/?response={{response}}'
value="{{response}}">{{response}}</a></li>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
var options = {
"key": "rzp_test_rpDFJlAD0LDl8Y",
"subscription_id": "{{ sub_id }}",
"name": "My Billing Label",
"description": "Auth txn for sub_8seKGNhVEOwnjj",
"handler": function (response){
// alert(response.razorpay_payment_id);
document.getElementById("url_call").click(response);
}
};
var rzp1 = new Razorpay(options);
document.getElementById('rzp-button').onclick = function(e){
rzp1.open();
}
</script>
In the above code I want to variable response from在上面的代码中,我想从
"handler": function (response){
// alert(response.razorpay_payment_id);
document.getElementById("url_call").click(response);
}
to到
<li hidden><a id="url_call" href='/paytm/response/?response={{response}}'
value="{{response}}">{{response}}</a></li>
I think the way im doing is wrong.我认为我的做法是错误的。 Could soemone help me with this?
soemone 能帮我解决这个问题吗? Thanks.
谢谢。
You can set the value of href
attribute as:您可以将
href
属性的值设置为:
document.getElementById('url_call').setAttribute('href', '/paytm/response/?response='+response);
Note
<a
tag does not havevalue
attribute.注意
<a
标签没有value
属性。 Click here to learn about valid attributes单击此处了解有效属性
If you insist to change the value of value
attribute, do this:如果您坚持要更改
value
属性的value
,请执行以下操作:
document.getElementById('url_call').setAttribute('value', response);
To change the text of <a
tag use:要更改
<a
标签的文本,请使用:
document.getElementById('url_call').innerText = response;
If you want all of the above changes, your final code will look like:如果您想要上述所有更改,您的最终代码将如下所示:
"handler": function (response){
var el = document.getElementById('url_call');
el.setAttribute('href', '/paytm/response/?response='+response);
el.setAttribute('value', response);
el.innerText = response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.