$('.selector').attr("checked", true);
<s:iterator value="jobSelect" id="jobLink2"> <s:iterator value="jobLink2" id="job2"> var arr = $('.selector'); var a = ${job2.id}; $('.selector').each(function(){ if($(this).val()== ${job2.id}){ $(this).attr("checked", true); } }); </s:iterator> </s:iterator>
AJAX绑定Select下拉框的选项:
方法一:
<select id="TypeStr" />
function BindDropDownList() { $("#TypeStr").html(""); $.getJSON("NoticeHandler.ashx?bz=BindDropDownList", null, function (json) { $.each(json, function (i,val) { $.each(val,function(){ var a = this.id + this.typestr; $("#TypeStr").append($("<option></option>").val(this.id).html(this.typestr)) }) }); }); $("<option></option>").val("").html("").appendTo("#TypeStr"); }
获取选中的文本值:
var selT = $('#TypeStr option:selected').text();
context.Response.Write(EDU.COMMON.PublicMethod.userjsondata("select * from ERPGongGaoType order by orderby "));
备注:
//StringBuilder sb = new StringBuilder(); //DataTable dt = new DataTable(); //if (dt == null) // return; //if (dt.Rows.Count == 0) //{ // return; //} //else //{ // sb.Append("["); // for (int i = 0; i < dt.Rows.Count; i++) // { // sb.Append("{"ID":"" + dt.Rows[i]["ID"].ToString() + "","Name":"" + dt.Rows[i]["Name"].ToString() + "","Age":" + dt.Rows[i]["Age"].ToString() + ","Tel":"" + dt.Rows[i]["Tel"].ToString() + ""},"); // } // sb.Remove(sb.Length - 1, 1); // sb.Append("]"); //} //context.Response.ContentType = "application/json"; //context.Response.ContentEncoding = System.Text.Encoding.UTF8; //context.Response.Write(sb.ToString());
方法二:用LigerUI:
var type=<%=EDU.COMMON.PublicMethod.GetSelectJson(EDU.DBUtility.DbHelperSQL.GetDataTable("SELECT id,typestr as text FROM [ERPGongGaoType] order by orderby")) %>;
typeS = $("#TypeStr").ligerComboBox({
data: type,
});
//获取值
if(typeS != null){
var selT = typeS.getText();
if (selT != "") {
where += " And TypeStr = '" + selT + "'";
}
}