在输入之前放置标签

时间:2013-10-31 11:55:09

标签: jquery

当我使用.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().after()时没有任何反应。我也没有收到任何错误消息。这是jquery输入处理的问题吗?

所需的输出是车辆: _ __ _ __ _ _ (双线换行)

1 个答案:

答案 0 :(得分: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