大佬教程收集整理的这篇文章主要介绍了Jquery改名称属性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$(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) { $("#" + id).attr('classname','SELEcted'); $("#" + id).attr('id','sel' + rowIndeX); $("#" + id).attr('name','sel' + rowIndeX); // this never works 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); $.each(data,function (GetSubCatergories,Category) { $('#parent_id').append($("<option></option>"). attr("value",Category.category_id). text(Category.Name)); }); } }); } }); });
$("#" + id).attr('id','sel' + rowIndeX); $("#" + id).attr('name','sel' + rowIndeX); // this can't ever work
$("#" + id).attr('id','sel' + rowIndeX) .attr('name','sel' + rowIndeX);
或者,重新排序语句,以便在更改id之前更改名称(和/或其他方式):
$("#" + id).attr('name','sel' + rowIndeX); $("#" + id).attr('id','sel' + rowIndeX);
您还可以将选择分配给变量:
var $el = $("#" + id); $el.attr("id",'sel' + rowIndeX); ...
以上是大佬教程为你收集整理的Jquery改名称属性全部内容,希望文章能够帮你解决Jquery改名称属性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。