Example, js traverses radio content.
Pay attention to two things: one is how to get the value, and the other is how to traverse document.getElementById("userlist").userid; This is a method of taking the value of the name of the control element based on the id of the form. You can also use document.getElementsByName("userid") to get it directly The difference between getElementById and getElementsByName. GetElementById can only select a single control when getting radio type elements. When getElementsByName gets radio type elements, it takes out the entire radio array. If you must use getElementById, you can first use getElementById to get the entire form like the above code. The id. Followed by the radio name Now we know that document.getElementsByName("userid") is to get an array. The elements in the array are all the elements with the name radionum in the DOM tree. Even if there is only one radio, it is an array containing only one element. Document.all.userid is different. It gets a reference to the userid element in the page. When there are multiple radios in the page, it returns an array. If the page only contains one radio, you get this radio. Object reference. Since what you get at this time is not an array, you cannot traverse the array to make a judgment. js function code:
|