Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to append a query string parameter to a href on a page using some JS:

var url = "http://www.sitetest.com?source=" + value;
var element = document.getElementById('thislink');
element.setAttribute("href",url);

HTML

<a href="#" id="thislink">TEST THIS LINK</a>

So whatever parameter is in the URL needs to append to the link, its working however it puts in the current URL not the one I specify in "var url"? Thanks!

Live link here: http://partnerweb.moneycorp.com/test-js-get-url.html?pc=tmgppc5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
263 views
Welcome To Ask or Share your Answers For Others

1 Answer

On your test page, have you checked the console?

Uncaught ReferenceError: value is not defined

The posted code will work fine if you assign a value to the value variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...