2
我遇到了这个jQuery函数的问题,重命名id,类和下拉列表名称的功能部分只适用于第一个下拉菜单,后续的不工作,任何想法?jQuery怀疑命名约定问题
我怀疑它可能与命名约定有关,如cat.parent_id,但它是asp.net mvc模型绑定所必需的。
$(document).ready(function() {
$("table select").live("change", function() {
var id = $(this).attr('id');
if ($(this).attr('classname') != "selected") {
var rowIndex = $(this).closest('tr').prevAll().length;
$.getJSON("/Category/GetSubCategories/" + $(this).val(), function (data) {
if (data.length > 0) {
//problematic portion
$("#" + id).attr('classname', 'selected');
$("#" + id).attr('name', 'sel' + rowIndex);
$("#" + id).attr('id', 'sel' + rowIndex);
var position = ($('table').get(0));
var tr = position.insertRow(rowIndex + 1);
var td1 = tr.insertCell(-1);
var td2 = tr.insertCell(-1);
td1.appendChild(document.createTextNode('SubCategory'));
var sel = document.createElement("select");
sel.name = 'parent_id';
sel.id = 'parent_id';
sel.setAttribute('class', 'unselected');
td2.appendChild(sel);
$('#parent_id').append($("<option></option>").attr("value", "-1").text("-please select item-"));
$.each(data, function (GetSubCatergories, Category) {
$('#parent_id').append($("<option></option>").
attr("value", Category.category_id).
text(Category.name));
});
sel.name = 'cat.parent_id';
sel.id = 'cat.parent_id';
}
});
}
});
});
你是否多次使用id =“parent_id”? – 2010-04-29 11:37:49
不我不是,我重命名控件,所以只有1将有cat.parent.id作为ID和名称 – user327087 2010-04-29 11:39:27