我有一个JQuery函数,试图改变元素的id,名称和类.id和类更改似乎有效,但出于一些奇怪的原因,尝试更改元素的名称永远不会起作用.
$(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 …Run Code Online (Sandbox Code Playgroud) jquery ×1