-1

当我使用.before().after()

this.vehicle = $('<input>');

this.vehicle.attr({
    id: "invoiceItemVehicle",
    name: "invoiceItemVehicle",
    class: "invoiceItemControl"
});
this.vehicle.before('<label>Vehicle</label>');
this.vehicle.after('<br /><br />');

由于某些原因,

this.vehicle.append('<label>Vehicle</label>'); 

会将标签放在输入中,但是当我使用.before()and时没有任何反应.after()。我也没有收到任何错误消息。这是 jquery 输入处理的问题吗?

所需的输出是 Vehicle: _ __ _ __ _ _(双换行符)

4

1 回答 1

0

试试 jQuery wrap() 函数。

用于测试的 HTML:

<div class="test"></div>

和 JS:

this.vehicle = $('<input>');

this.vehicle.attr({
    id: "invoiceItemVehicle",
    name: "invoiceItemVehicle",
    class: "invoiceItemControl"
});
this.vehicle.wrap('<label>Vehicle: </label>');
$('.test').append(this.vehicle.parent());

http://cssdeck.com/labs/yuemvbp5

于 2013-10-31T12:03:10.317 回答