javascript method of implementing linked radio effects
- 2020-06-12 08:34:11
- OfStack
This article gives an example of how javascript implements linked radio effects. Share to everybody for everybody reference. Specific implementation methods are as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Link to the radio </title>
<script type="text/javascript">
function IniEvent() {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
links[i].onclick = LinkOnClick;
}
}
function LinkOnClick() {
var links = document.getElementsByTagName("a");
//links It's used in two places (IniEvent Also used to ),
// Be careful not to throw links Put it in a global variable,
// Try not to use global variables,
// If you have too much repetitive code, put the code in 1 Of the public functions
for (var i = 0; i < links.length; i++) {
if (links[i] == this) {
links[i].style.background = "red";
}
else {
links[i].style.background = "white";
}
}
window.event.returnValue = false;// Prevent navigation to the site
}
</script>
</head>
<body onload="IniEvent()">
<a href="http://www.baidu.com"> baidu </a><br />
<a href="http://www.sohu.com"> sohu </a><br />
<a href="https://www.ofstack.com"> The home of the script </a><br />
<a href="http://www.tudou.com"> potatoes </a><br />
<a href="http://www.csdn.com">CSDN</a><br />
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.