简体   繁体   中英

Change href link based on querystring parameter with JavaScript

I have some JavaScript:

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

It changes the parameter on a href link based on the one currently in the querystring (rp=):

<a href="#" id="url">LOOK A LINK</a>

That works however it puts in the current URL and not one I specifiy ie http://www.google.com/ , what needs to change in the code to do this?

Many thanks.

This error will be solved when you define "value"

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

try removing this variable OR define it.

You can see the console for the error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM