function checkFootball() { $(" [name='item']:checkbox").each(function () { if (this.value == 'football') { this.checked = true; } }) }
Note: The specific purpose is to retrieve data from the background and display it. Here we do not use jQuery's attr() and val() methods to set the selection and get the value of the current checkbox. Instead, we use JavaScript's native Dom method, which is more effective than creating a jQuery object 2. Radio button operation html code:
$(document).ready(function() { // Data initialization Select B. $('[name="item"]:radio').each(function() { if (this.value == 'B') { this. checked = true; } }); // Bind the event of getting the letter $('#getLetter').click(getLetter); });
$(document).ready(function() { $('#addOptions').click(addOptions); // Add elements to the list $('#getSelectedOption'). click(getSelectedOption); // Get the selected element $('#clearOptions').click(clearOptions); // Clear the elements in the list $('#addOptions').click(); / / Trigger the add element event to the list });
function addOptions() { var selectContainer = $('#choose'); for (var i = 0 ; i < 5; i ) { var option = $('').text('choose' i).val(i); selectContainer .append(option); } }
function getSelectedOption() { /* Pop each element one by one*/ var options = $('#choose > option: selected'); $.each(options, function () { alert('option: ' this.value); }); /* Pop each element one by one, first Abbreviation for species*/ $('#choose > option:selected').each(function() { alert('option2: ' this.value); }); // Pop up the data directly. If it is a drop-down box, pop up the data directly. If it is a list and multiple data are selected // Data will be displayed separated by ',' alert('val: ' $('#choose').val()); }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn