µ±Ç°Î»Ö㺠´úÂëÃÔ >> WebÇ°¶Ë >> jquery radioÈ¡Öµ,checkboxÈ¡Öµ,selectÈ¡Öµ,radioÑ¡ÖÐ,checkboxÑ¡ÖÐ,selectÑ¡ÖÐ,¼°ÆäÏà¸É
  Ïêϸ½â¾ö·½°¸

jquery radioÈ¡Öµ,checkboxÈ¡Öµ,selectÈ¡Öµ,radioÑ¡ÖÐ,checkboxÑ¡ÖÐ,selectÑ¡ÖÐ,¼°ÆäÏà¸É

Èȶȣº96   ·¢²¼Ê±¼ä£º2012-11-10 10:48:51.0
jquery radioÈ¡Öµ,checkboxÈ¡Öµ,selectÈ¡Öµ,radioÑ¡ÖÐ,checkboxÑ¡ÖÐ,selectÑ¡ÖÐ,¼°ÆäÏà¹Ø

jQuery 1.3.2°æ±¾ÏµÄ
jquery radioÈ¡Öµ,checkboxÈ¡Öµ,selectÈ¡Öµ,radioÑ¡ÖÐ,checkboxÑ¡ÖÐ,selectÑ¡ÖÐ,¼°ÆäÏà¹Ø

ÉèÖÃ

»ñÈ¡Ò»×éradio±»Ñ¡ÖÐÏîµÄÖµ:var item = $('input[name=items][checked]').val();
»ñÈ¡select±»Ñ¡ÖÐÏîµÄÎı¾
var item = $("select[@name=items] option[@selected]").text();

»ñÈ¡select±»Ñ¡ÖÐÏîµÄÎı¾ :var item = $("select[name=items] option[selected]").text(); »ò$("select[name=items]").find("option:selected").text();

selectÏÂÀ­¿òµÄµÚ¶þ¸öÔªËØΪµ±Ç°Ñ¡ÖÐÖµ:$('#select_id')[0].selectedIndex = 1;

selectÏÂÀ­¿òvalue = 'val'µÄÔªËØΪµ±Ç°Ñ¡ÖÐÏî:$("select[name=items] option[value='val']").attr("selected","selected");

radioµ¥Ñ¡×éµÄµÚ¶þ¸öÔªËØΪµ±Ç°Ñ¡ÖÐÏî :$('input[@name=items]').get(1).checked = true; »ò$('input[name=items]').attr("checked", '1¡ä);

radioµÄvalue = 'val'µÄÔªËØΪµ±Ç°Ñ¡ÖÐÏî:$('input[name=items] [value='val']').attr("checked","checked");


»ñÈ¡Öµ:

Îı¾¿ò,Îı¾ÇøÓò:$("#txt").attr("value");

¶àÑ¡¿òcheckbox:$("input[name='checkbox':checked]").each(function(){

var val = $(this).val();

});

µ¥Ñ¡×éradio: $("input[type=radio][checked]").val();

ÏÂÀ­¿òselectµÄvalueÖµ: $('select').val();

ÏÂÀ­¿òselectÑ¡ÖеÄtext Öµ:$("select").find("option:selected").text();

¿ØÖÆ±íµ¥ÔªËØ:

Îı¾¿ò,Îı¾ÇøÓò:$("#txt").attr("value","); //Çå¿ÕÄÚÈÝ

$("#txt").attr("value",'11¡ä); //Ìî³äÄÚÈÝ

¶àÑ¡¿òcheckbox:
checkboxµÄµÚ¶þ¸öÔªËر»´ò¹´:$("input[name=items]").get(1).checked = true; //´ò¹´
$("input[name=items]").get(1).checked = false; //²»´ò¹´

checkboxµÄvalue='val'µÄÔªËØÇ°´ò¹´:$("input[name=item][value='val']").attr("checked",true); »ò$("input[name=item][value='val']").attr("checked","checked");

if($("input[name=item][value='val']").attr('checked')==true) //ÅжÏÊÇ·ñÒѾ­´ò¹´

µ¥Ñ¡×éradio: $("input[type=radio]").attr("checked",'2¡ä);//ÉèÖÃvalue=2µÄÏîĿΪµ±Ç°Ñ¡ÖÐÏî

ÏÂÀ­¿òselect: $("#sel").attr("value",'-sel3¡ä);//ÉèÖÃvalue=-sel3µÄÏîĿΪµ±Ç°Ñ¡ÖÐÏî

$("<option value='1¡ä>1111</option><option value='2¡ä>2222</option>").appendTo("#sel")//Ìí¼ÓÏÂÀ­¿òµÄoption

$("#sel").empty();//Çå¿ÕÏÂÀ­¿ò

jQuery»ñÈ¡RadioÑ¡ÔñµÄValueÖµ
´úÂë

$("input[name='radio_name'][checked]").val(); //Ñ¡Ôñ±»Ñ¡ÖÐRadioµÄValueÖµ
$("#text_id").focus(function(){//code...}); //ʼþ µ±¶ÔÏótext_id»ñÈ¡½¹µãʱ´¥·¢
$("#text_id").blur(function(){//code...}); //ʼþ µ±¶ÔÏótext_idʧȥ½¹µãʱ´¥·¢
$("#text_id").select(); //ʹÎı¾¿òµÄVlaueÖµ³ÉÑ¡ÖÐ״̬
$("input[name='radio_name'][value='ҪѡÖÐRadioµÄValueÖµ'").
attr("checked",true); //¸ù¾ÝValueÖµÉèÖÃRadioΪѡÖÐ״̬

jQuery»ñÈ¡CheckBoxÑ¡ÔñµÄValueÖµ

$("input[name='checkbox_name'][checked]"); //Ñ¡Ôñ±»Ñ¡ÖÐCheckBoxÔªËصļ¯ºÏ Èç¹ûÄãÏëµÃµ½
ValueÖµÄãÐèÒª±éÀúÕâ¸ö¼¯ºÏ
$($("input[name='checkbox_name'][checked]")).
each(function(){arrChk+=this.value + ',';});//±éÀú±»Ñ¡ÖÐCheckBoxÔªËصļ¯ºÏ µÃµ½ValueÖµ
$("#checkbox_id").attr("checked"); //»ñÈ¡Ò»¸öCheckBoxµÄ״̬(ÓÐûÓб»Ñ¡ÖÐ,·µ»Øtrue/false)
$("#checkbox_id").attr("checked",true); //ÉèÖÃÒ»¸öCheckBoxµÄ״̬ΪѡÖÐ(checked=true)
$("#checkbox_id").attr("checked",false); //ÉèÖÃÒ»¸öCheckBoxµÄ״̬Ϊ²»Ñ¡ÖÐ(checked=false)
$("input[name='checkbox_name']").attr
("checked",$("#checkbox_id").attr("checked"));//¸ù¾Ý3,4,5Ìõ,Äã¿ÉÒÔ·ÖÎö·ÖÎöÕâ¾ä´úÂëµÄÒâ˼
$("#text_id").val().split(","); //½«TextµÄValueÖµÒÔ','·Ö¸ô ·µ»ØÒ»¸öÊý×é

  Ïà¹Ø½â¾ö·½°¸