Get Select:
Get selected text:
$("#ddlRegType").find("option:selected").text();
Get selected value:
$(" #ddlRegType ").val();
Get the selected index of select:
$("#ddlRegType ").get(0).selectedIndex;
Set select:
Set the selected index of select :
$ ("#ddlregtype") .get (0) .selectEdindex = Index; // Index was the Value selected by SELECT:
$ ("#ddlregtype") .attr ("Value ","Normal");
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
Set select Select text:
var count=$("#ddlRegType option").length;
for(var i=0;i
}
$( "#select_id option[text='jQuery']").attr("selected", true);
Set the select option item:
$("#select_id").append(""); //Add an option
$("#select_id").prepend("
$("#select_id option:last").remove(); //Remove the Option with the largest index value
$("#select_id option[index='0 ']").remove(); //Delete the Option
with index value 0 $("#select_id option[value='3']").remove(); //Delete Option
with index value 3 $("#select_id option[text='4']").remove(); //Delete the Option with TEXT value 4
Clear Select:
$("#ddlRegType ").empty();
jquery Get value:
.val()
.text()
Set value
.val('Set value here')
$("document").ready(function (){
$("#btn1").click(function(){
$("[name='checkbox']").attr("checked",'true');//Select all
})
$("#btn2").click(function(){
$("[name='checkbox']").removeAttr("checked");//Deselect all
})
$("#btn3 ").click(function(){
$("[name='checkbox']:even").attr("checked",'true');//Select all odd numbers
})
$("#btn4 ").click(function(){
$("[name='checkbox']").each(function(){//Inverse selection
if($(this).attr("checked")){
$ (this).removeAttr("checked");
}
else{
$(this).attr("checked",'true');
}
})
})
$("#btn5"). click(function(){//Output the selected value
var str="";
$("[name='checkbox'][checked]").each(function(){
str+=$(this). val()+"rn";
//alert($(this).val());
})
alert(str);
})
})
========= ================================================== =======
============================================ =========================
jQuery.fn.size = function()
{
{ return jQuery(this).get(0).options.length;
}
//Get the index of the selected item
jQuery.fn.getSelectedIndex = function()
{ J Return jquery (this) .get (0) .selectEdindex;
}
// Get the current selected text
jquery.fn.getSelectExt = function () {
if (this.size () == 0)
)
{
return "下拉框中无选项";
}
else
{
var index = this.getSelectedIndex();
return jQuery(this).get(0).options[index].text;
}
}
//Get the value of the currently selected item
jQuery.fn.getSelectedValue = function()
{
if(this.size() == 0)
{ return "No selected value in the drop-down box";
}
else
{
jQuery(this).get (0).value = value;
}
//Set the first item in the select as text to be selected
jQuery.fn.setSelectedText = function(text)
{
var isExist = false;
var count = this. size();
for(var i=0;i
{ jQuery(this) .get(0).options[i].selected = true;
{ }
}
//Set the selected index item
jQuery.fn.setSelectedIndex = function(index)
{
var count = this.size();
if(index >= count || index < 0)
{T Alert ("Selecting the index exceeds the range"); Item
jQuery.fn.isExistItem = function(value)
{
var isExist = false;
var count = this.size();
for(var i=0;i
{
isExist = true; is text, the value is value, if the value already exists, it will prompt
jQuery.fn .addOption = function(text,value) { jQuery(this).get (0).options.add(new Option(text,value));
}
}
//Delete the item whose value is value in the select. If the item does not exist, it will prompt
jQuery.fn.removeItem = function( value)
{
if(this.isExistItem(value))
{ var count = this.size();
for(var i=0;i
}
}
//Delete the item with the specified index in select
jQuery.fn.removeIndex = function(index)
{
var count = this.size();
if( index > .remove(index);
}}} // Delete the selected item
jquery.fn.removeSelect = Function () {
var index = this.getSelectEdex (); Le // Clear Select All items in
jQuery.fn.clearAll = function()
{
Drop down menu operations To summarize related articles, please pay attention to the PHP Chinese website!