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="">
<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 
<body onload="IniEvent()">
<a href=""> baidu </a><br />
<a href=""> sohu </a><br />
<a href=""> The home of the script </a><br />
<a href=""> potatoes </a><br />
<a href="">CSDN</a><br />

Hopefully, this article has been helpful in your javascript programming.

Related articles: