遍历option和添加、移除option
function changeShipMethod(shipping){ var len = $("select[@name=ISHIPTYPE] option").length; if(shipping.value != "CA"){ $("select[@name=ISHIPTYPE] option").each(function(){ if($(this).val() == 111){ $(this).remove(); } }); }else{ $("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]")); } }
取得下拉选单的选取值
$('#testSelect option:selected').text(); $("#testSelect").find('option:selected').text(); $("#testSelect").val();
得到下拉菜单的选中项的文本(注意中间有空格)
var cc1 = $(".formc select[@name='country'] option[@selected]").text();
得到下拉菜单的选中项的值
var cc2 = $('.formc select[@name="country"]').val();
得到下拉菜单的选中项的ID属性值
var cc3 = $('.formc select[@name="country"]').attr("id");
清空下拉框//$("#select").html('');
$("#select").empty();
添加下拉框的option
$("<option value='1'>1111</option>").appendTo("#select")
得到单选框的选中项的值(注意中间没有空格)
$("input[@type=radio][@checked]").val();
设置单选框value=2的为选中状态.(注意中间没有空格)
$("input[@type=radio][@value=2]").attr("checked",'checked');
得到复选框的选中的第一项的值
$("input[@type=checkbox][@checked]").val();
遍历获取选中的复选框的值
$("input[@type=checkbox][@checked]").each(function(){ alert($(this).val()); });
取消选中
$("#chk1").attr("checked",'');
选中
$("#chk2").attr("checked",true);
判断是否已经选中
if($("#chk1").attr('checked')==undefined){} //