Joke Collection Website - Public benefit messages - How to get all the values ??of checkbox
How to get all the values ??of checkbox
jquery’s traversal method can obtain the desired selected value of the check box
$("input: checkbox: checked").each(function(index, element)); / / Execute the function for all selected checkboxes. The value of each checkbox can be taken out from the function body
$("input:checkbox:checked").map(function(index,domElement)) ; // Generate new jQuery objects for all selected checkboxes through function return values
Example demonstration: click the button to get the selected value of the checkbox
Create Html element
lt;div class="box"gt;
lt;spangt;Click the button to get the selected value of the checkbox:lt;/spangt;
lt;div class=" content"gt;
lt; input type='checkbox' name='message' value='1'/gt; send text message
lt; input type='checkbox' name ='message' value='2'/gt;Send mail
lt;/divgt;
lt;input type="button" value="Submit"gt;
p>lt;/divgt;
Set css style
div.box{width: 300px; padding: 20px; margin: 20px; border: 4px dashed #ccc; }
div.boxgt; span{color: #999; font-style: italic;}
div.content{width: 250px; margin: 10px 0; padding: 20px; border: 2px solid #ff6666;}
Write jquery code
$(function(){
$("input: button").click(function () {
text = $("input: checkbox[name='message']: checked").map(function(index,elem) {
return $(elem ).val();
}).get().join(', ');
alert("The value of the selected checkbox is: " text);
p>});
});
- Previous article:How to fill in the SMS authorization code
- Next article:How did Deng Chao call Sun Li among everyone, and why did Sun Li blush?
- Related articles
- Why didn't twitter respond when it created the account?
- What is the telephone number of Heze 1 10?
- What about fraudulent text messages?
- Can the wisdom tree mobile phone exam be cut out?
- Summary model essay on anti-fraud education and publicity activities (select 6 articles)
- Information about Liu Xiang.
- What if the bank card is locked?
- Warm reminder from China Mobile: Recently, some criminals have sent short message links such as refunds by impersonating online financial institutions such as Yu 'ebao and Licaitong, asking for bodies
- Do swans need to cancel their personal information with SMS verification code when they go home?
- What does it mean to activate mobile banking?