admin管理员组文章数量:1425799
I have in a variable (var lan= urlParam('language')
) the selected language.
I want to pass this language as parameter (without using PHP) in a url in an "a
" tag, like this:
<a href=".aspx?languageCode=lan">
but it doesn't work.
I am waiting for your answers. Thank you a lot.
I have in a variable (var lan= urlParam('language')
) the selected language.
I want to pass this language as parameter (without using PHP) in a url in an "a
" tag, like this:
<a href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=lan">
but it doesn't work.
I am waiting for your answers. Thank you a lot.
Share Improve this question edited Sep 14, 2011 at 13:45 Quasdunk 15.2k3 gold badges39 silver badges47 bronze badges asked Sep 14, 2011 at 13:36 AlekaAleka 111 gold badge1 silver badge2 bronze badges 1- You want to dynamically, using JavaScript, add a new GET parameter to every link that is on the page. Is that correct? – Jan Hančič Commented Sep 14, 2011 at 13:38
2 Answers
Reset to default 2Your url is inside a string, so it won't put the value of your variable, but just the string "lan".
Give an ID to your link, so you can take it and change its url with javascript.
<a id="foo" href="http://hotelsbined.sitewish.gr/HotelNameSearch.aspx">
Then, with JS
document.getElementById('foo').setAttribute('href', 'http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=' + lan);
If I understand correctly, you can just use document.write to print the link and add the variable as the language parameter.
<script type="text/javascript">document.write("<a href=\"http://hotelsbined.sitewish.gr/HotelNameSearch.aspx?languageCode=" + lan + "\">link description</a>");</script>
本文标签: javascriptpassing parameter to url via ltagt tag int htmlStack Overflow
版权声明:本文标题:javascript - passing parameter to url via <a> tag int html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745453471a2658992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论