Home >Web Front-end >JS Tutorial >jquery uses bits and pieces of function code_jquery

jquery uses bits and pieces of function code_jquery

WBOY
WBOYOriginal
2016-05-16 18:06:301086browse

1. Simple button js events are used to judge and display prompts

Copy code The code is as follows:




2. Processing of drop-down lists
Copy code The code is as follows:

function dropTypeChange()
{
var sel = $("#<%=dropType.ClientID %> option:selected").val();
if(sel== "-1")
{
$("#<%=txtNo.ClientID %>").attr('disabled',true);
}
else
{
$("#<%=txtNo.ClientID %>").attr('disabled',false);
}
}


/ /Get the value of the first option
$('#test option:first').val();
//The value of the last option
$('#test option:last'). val();
//Get the value of the second option
$('#test option:eq(1)').val();
//Get the selected value
$ ('#test').val();
$('#test option:selected').val();
//Set the option with value 2 to the selected state
$('# test').attr('value','2');
//Set the first option to be selected
$('#test option:last').attr('selected','selected' );
$("#test").attr('value' , $('#test option:last').val());
$("#test").attr('value ' , $('#test option').eq($('#test option').length - 1).val());
//Get the length of select
$('#test option ').length;
//Add an option
$("#test").append("");
$( "").appendTo("#test");
//Add and remove selected items
$('#test option:selected'). remove();
//The specified item is selected
$('#test option:first').remove();
//The specified value is deleted
$('#test option') .each(function(){
if( $(this).val() == '5'){
$(this).remove();
}
});
$('#test option[value=5]').remove();
//Get the label of the first Group
$('#test optgroup:eq(0)').attr ('label');
//Get the value of the first option under the second group
$('#test optgroup:eq(1) :option:eq(0)').val();
Statement:
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