简体   繁体   中英

Changing the href attribute on checked

I'm working on a web page that contains a radio buttons group.

When one of these buttons get checked I need to change the href attribute of a link element (use different CSS file), How can I do that using Java script and html?

I tried getElementById() but the innerHtml attribute doesn't help, do you have any simple solution?

这应该工作:

document.getElementById('myStylesheet').href = 'http://example.com/new/href/link';
var input = document.getElementById("inputid");
if (input.checked){
var aElem = document.getElementById("aid");
aElem.href = "newurl";
}

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