select的操做html
$("#txtaddprojecturl").change(function(){ $("#addprojectname").html(""); });
//函數形式
$("#YesOrNo").change(YesOrNoChange);
var BrandID= $("#addbrand ").val();
var BrandName= $("#addbrand option:selected").text();
$("#addbrand ").val(BrandID);
$("#brandCity option").filter(function(){ return this.text == row.BrandCity; }).prop('selected',true);
$("#mySelect2 option").each(function(){this.selected =(this.text == text2);});
$("#mySelect2 option:contains("+text2+")").prop('selected',true);
$("#mySelect1").find("option[text="+ text1 +"]").attr("selected",true); $("#my-Select option[text="+ myText +"]").prop("selected",true);
$("#searchCity").prepend('<option value="-1">請選擇</option>');
$("#searchCity").append('<option value="-1">請選擇</option>');
//加載數據 var brandSelect = $("#addbrand"); brandSelect.empty(); brandSelect.append('<option value="">請選擇</option>'); var brandData = result.Data; //根據後臺返回的Data if(brandData !=null&& brandData.length >0){ for(var i =0; i < brandData.length; i++){ var oneData = brandData[i]; brandSelect.append('<option data-cityid="'+ oneData.CityID+'" data-cityname="'+ oneData.CityName+'" value="'+ oneData.ID +'">'+ oneData.BrandName+'</option>'); } }
其餘添加許多option的方法
$("#addbrand").empty().append('<option value="">請選擇</option>');
$("#addbrand").empty();
$("#sltaddcity option[value='-1']").remove();
<inputclass="IsBrand"type="radio"name="IsBrand"value="1"checked="checked"/>
是
<inputclass="IsBrand"type="radio"name="IsBrand"value="0"/>
否
$("input:radio").click(function(){ if($(this).val()=="1"&& $(this).prop("checked")==true){ $(".brand").show(); $(".project").hide(); }else{ $(".brand").hide(); $(".project").show(); } });
$(".IsBrand").each(function(){ var _this = $(this); if(_this.val()== row.IsBrandPromotion){ _this.prop("checked",true); } });
var a = $(".IsBrand"); $(a[0]).prop("checked",true);
$(".IsBrand").click(function(){ if($(this).val()=="1"&& $(this).prop("checked")==true){ $(".brand").show(); $(".project").hide(); }else{ $(".brand").hide(); $(".project").show(); } });
2.獲得radio的值
var IsBrandPromotion= $(".IsBrand:checked").val();
$(".IsBrand").prop("disabled",true);
$("#txtaddprojecturl").val("");
$("#txtaddprojecturl").val(row.ProjectUrl);
var b = $(".tableMediaData :checkbox");
var arrChk = $(".mediachk:checked");
$(arrChk).each(function(){ MediaID+="'"+ $(this).val()+"',"; });
設置
ProjectName= $.trim($("#addprojectname").html());
$("#addprojectname").html(row.ProjectName);
$("#addprojectname").text("");