0
var lastname = jQuery('[name="dc_contributor_author_first_'+i+'"]');
if (lastname==null)
    exit;
var orderbox = "<td nowrap='nowrap'><input type='text' size=1 id='author_order_"+i+"' value="+i+" onchange=updateBoxes(this.value,"+i+")></td>";
jQuery(orderbox).insertAfter(lastname.parent());

结果为

<input type="text" )="" 1="" onchange="updateBoxes(this.value," value="1" id="author_order_1" size="1">

但是当我从 updateBoxes 中删除空间作为"onchange=updateBoxes(this.value,"+i+")"函数时,它工作得很好,结果如下。为什么?

<input type="text" onchange="updateBoxes(this.value,1)" value="1" id="author_order_1" size="1">
4

2 回答 2

1

尝试改变:

var orderbox = "<td nowrap='nowrap'><input type='text' 
size=1 id='author_order_"+i+"' value="+i+" 
onchange=updateBoxes(this.value,"+i+")></td>";

至:

var orderbox = "<td nowrap='nowrap'><input type='text' 
size='1' id='author_order_"+i+"' value='"+i+"' 
onchange='updateBoxes(this.value,"+i+")'></td>";

适当的属性引用可能对 jQuery 解析器更友好。

于 2013-10-28T19:00:10.910 回答
0

不知道是什么lastname = if(lastname==null) exit;意思,但这里是你应该如何创建和插入这些元素:

var td  = $('<td />', {
        'nowrap':'nowrap'
    }),
    inp = $('<input />', {
        type  : 'text',
        size  : '1',
        id    : 'author_order_'+i,
        value : i,
        on    : {
                change: function() {
                    updateBoxes(this.value, i);
                }
        }
    });

$('[name="dc_contributor_author_first_'+i+'"]').parent().after(td.append(input));
于 2013-10-28T18:48:07.093 回答