我有使用Jquery从数据库中检索到的记录,这些记录的值和复选框附加在div上, 我目前希望在检索记录时检查数据库中ID为= 5的记录。 请任何帮助
下面是用于检索记录并将每个记录附加到div中的代码。
function loadState(xxxxxxTypeDDL) {
if ($(xxxxxxTypeDDL).val() == "") {
clearState(xxxxxxTypeDDL);
return;
}
$.ajax({
url: "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
global: false,
cache: false,
dataType: 'json',
timeout: 30000,
beforeSend: function() {
$("#ajax-loading-placeholder").html('<img src="/Images/ajax-loader.gif" alt="...Loading" /> ...Loading').dialog({
autoOpen: false,
width: 32,
height: 60,
modal: true,
resizable: false
}).dialog("widget").find(".ui-dialog-titlebar").remove();
// alert("Weldone Dude");
$("#ajax-loading-placeholder").dialog('open');
clearState(xxxxxxTypeDDL);
},
success: function(data) {
$('#ajax-loading-placeholder').dialog('destroy').html('');
var htmlToInsert = "";
if (data == null) {
$("<div></div>").text("No State found matching your selection criteria").dialog({
autoOpen: false,
modal: true,
title: 'Select Required State',
buttons: {
"Ok": function() {
$(this).dialog('destroy').html('');
}
}
}).dialog("open");
clearState(xxxxxxTypeDDL);
$(xxxxxxTypeDDL).val("");
$("#selected-state").hide();
return;
}
$(data.State).each(function() {
var input = "<div style='margin-bottom:5px' class='retrieved-state-list'><input type='checkbox' id='";
input += "RetrievedState' value='";
input += this.ID;
if ($.inArray(this.ID.toString(), data.SelectedState) > -1) {
input += "' checked='checked";
}
input += "' </input><span style='display:none'>" + this.Name + "</span>";
input += "<span>" + this.Description + "</span></div>"
htmlToInsert += input;
});
答案 0 :(得分:3)
对于显示信息元素中的每一行,
<div data-id="<IDs>" class="display:none"></div>
在js中,通过.attr()
链接http://api.jquery.com/attr/
JQuery.each($('div[data-id]'), function(i, val) {
if (val.attr('data-id') == "5") {
// Do some stuff here
}
})