


'Event' triggered by radio selection in HTML-CSS group_form special effects
Because of a radio button problem with the God of Death, many people came out to talk nonsense. Alas, even this rookie level person also came out to fish in troubled waters. I accidentally touched one.
First of all, let’s look at a piece of code dug out from Baidu. This is where I started.
<script> <br>function checkradio() <br>{ <br> for(i=0;i<document.form1.Fruit.length;i ) <BR> { <BR> if(document.form1.Fruit[i].checked) <BR> { > alert("Your favorite fruit is:" document.form1.Fruit[i].nextSibling.nodeValue); <BR> ;form name="form1"> <br>Your favorite fruit is:<br> <br><input type=radio value="Fruit1" name="Fruit" checked>Apple <br>< input type=radio value="Fruit2" name="Fruit">Banana <br><input type=radio value="Fruit3" name="Fruit">Strawberry <br><input type=radio value= "Fruit4" name="Fruit">Pineapple <br><input type=button value="Select" onclick="checkradio()"> <br></form> <br><br><br>The purpose of this code is to determine the selected value. <br><br>The desired effect now is to give a prompt if each option is empty. The following code is the effect after the changes <br> </div> Program code <br><script> <br>function checkradio() <br>{ <br> var j=0; <br> for(i=0;i<document.form1.Fruit.length;i ) <br> { <br> if(document .form1.Fruit[i].checked==true) <br> { <br> alert("You selected" document.form1.Fruit[i].nextSibling.nodeValue); <br> { <br> //break;This break After Feifei pointed it out, it is invalid, remove <br> } else{ <br> j=j 1; Alright! "); <br> The fruit is:<br> <br><input type=radio value="Fruit1" name="Fruit"> <br>Apple <br><input type=radio value="Fruit2" name="Fruit ">Banana<br><input type=radio value="Fruit3" name="Fruit">Strawberry<br><input type=radio value="Fruit4" name="Fruit">Pineapple<br><input type=button value="Select" onclick="checkradio()"> <br></form> <br><br><br>Later I saw a clearer one written by Chen A piece of code, please post it here. <br> (Note: For the convenience of testing, I changed it a bit, but the idea is still his) <br><br><br><br><br>Copy the code<br><br><br> The code is as follows:<br><div class="codebody" id="code32343"> <br><script> <br>function checkradio() <br>{ <br> var flag=false; <br> for(var i=0;i<=document.form1.Fruit.length- 1;i ) <BR> alert ("^_^"); <BR> return false; <BR> }else{ <BR> alert("Hero, just choose one!"); <BR> } <BR>} <BR> </script>
The radio selection is over. Boss Feifei didn’t give up and came up with a code for the check box at night.
Copy code
<script> <br> var j=document.getElementsByName("Fruit"); <br>function allche(){ <br> for(var i=0; i <j.length; i ){ <BR> if(document.form1.Fruit[i].checked!=true) document.form1.Fruit[i].checked= document.form1.suoy.checked; <BR> if(document.form1.Fruit[i].checked==true) document.form1.Fruit[i].checked= document.form1.suoy.checked; <BR> } <BR>} <BR>function checkall(){ <BR>var aa=0 <BR> for(var i=0; i <j.length; i ){ <BR> if(document.form1.Fruit[i].checked == true) aa ; <BR> aa!=j.length ? document.form1.suoy.checked=false : document.form1.suoy.checked=true; <BR> } <BR>} <BR>function checkradio(){ <BR>var a=0 <BR>var list="" <BR>for(var i=0; i<j.length;i ) <BR>if (document.form1.Fruit[i].checked== true){ <BR>list=="" ? list=document.form1.Fruit[i].value : list=list "," document.form1.Fruit[i].value; <BR>} <BR>if (list!="") alert("你喜欢的水果是" list); <br><br>else{ <BR>a ; <BR>if (a==j.length)alert("大哥。你都不选我怎么知道你喜欢什么?");} <BR>} <br><br></script>
再来一段更简洁的代码、效果更好的关于复选的代码。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
