用jQuery添加首字母缩略词

时间:2014-01-30 21:47:14

标签: jquery html

我有一个具有此标记的HTMl字段:

<label for="id_data_path_ip_0">
<input class="radiolist inline" id="id_data_path_ip_0" name="data_path_ip" type="radio" value="Tool"> Same as Tool</label>

有没有办法用jQuery添加这个缩写?如果我正在编写HTML,它将如下所示:

<label for="id_data_path_ip_0">
<acronym class="help" title="This requires the setup of a remote mount.">?</acronym>
<input class="radiolist inline" id="id_data_path_ip_0" name="data_path_ip" type="radio" value="Tool"> Same as Tool</label>

2 个答案:

答案 0 :(得分:2)

如果您想在label之后找到它,那么您需要定位label代码的.after() ..

var abbr = '<abbr class="help" title="This requires the setup of a remote mount.">?</abbr>'
$('label[for="id_data_path_ip_0"]').after(abbr);

http://jsfiddle.net/gaby/hfEJ2/

演示

答案 1 :(得分:0)

不确定这是否是您所追求的,但您可以使用.before()在输入标记之前插入首字母缩略词:

$(".radiolist").before( "<acornym....." );

http://api.jquery.com/before/

相关问题