admin管理员组文章数量:1327713
I have captured 3 values from a datalist template using JavaScript, now I need to append these values into an existing anchor which is:
<a id="link" href='nextpage.aspx?id=<%#Eval("PlateId")%>&pp= #Eval("price")%>'>
I found the way to get the anchor href from JavaScript:
<script language='javascript' type="text/javascript" >
function addLink() {
var anchor = document.getElementById("link");
anchor.href = anchor + "&qty=";}
</script>
But, I can't add the js value after "&qty="
, I have tried adding the value like this:
anchor.href = anchor +"&qty=+Value+"
And with this:
anchor.href = anchor +"&qty='Value' "
I can't put it out of the quotation marks, because it won't display in the anchor.
I have captured 3 values from a datalist template using JavaScript, now I need to append these values into an existing anchor which is:
<a id="link" href='nextpage.aspx?id=<%#Eval("PlateId")%>&pp= #Eval("price")%>'>
I found the way to get the anchor href from JavaScript:
<script language='javascript' type="text/javascript" >
function addLink() {
var anchor = document.getElementById("link");
anchor.href = anchor + "&qty=";}
</script>
But, I can't add the js value after "&qty="
, I have tried adding the value like this:
anchor.href = anchor +"&qty=+Value+"
And with this:
anchor.href = anchor +"&qty='Value' "
I can't put it out of the quotation marks, because it won't display in the anchor.
Share Improve this question edited Feb 19, 2013 at 21:56 Flexo - Save the data dump♦ 88.8k22 gold badges201 silver badges281 bronze badges asked Feb 19, 2013 at 21:43 Carlos SilesCarlos Siles 712 silver badges6 bronze badges2 Answers
Reset to default 4anchor.href = anchor + "&qty="
should be
anchor.href = anchor.href + "&qty="
...otherwise you are trying to turn the link element into a string!
Meanwhile, you still need to keep Value
out of the quotation marks, otherwise the final text generated will always be exactly that text: Value
. If Value
is a variable and is not returning the value you expect (an empty or undefined value, for example), then you need to look at the code that declares it and change that.
Dynamically change
<a href=""></a>
href atrribute value (or) You can able to append the existing URL
Tips: 1 - Use the jQuery .attr() Method
$("selector").attr("href", newURL));
Tips: 2 - Use javascript element selector document.getElementById
example:
<a href="test.php" id="test">TEST URL</a>
var redirect_url = document.getElementById('test');
redirect_url.href = "new url";
(or)
document.getElementById('test').href = "newURL";
(or)
using setAttribute() method *Note:broken in IE
redirect_url.setAttribute("href", "new url");
本文标签: javascriptAppend values into an existing anchor hrefStack Overflow
版权声明:本文标题:javascript - Append values into an existing anchor href - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742214943a2434396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论