【问题标题】:Adding acronym with jQuery使用 jQuery 添加首字母缩写词
【发布时间】:2014-01-31 06:01:26
【问题描述】:

我有一个具有此标记的 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>

【问题讨论】:

  • &lt;acronym&gt; 实际上已在 HTML5 中被弃用,取而代之的是 &lt;abbr&gt;。不再区分缩写和首字母缩写词。

标签: jquery html


【解决方案1】:

如果您想要在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/的演示

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 感谢您的回复,但我打错了我想要的内容。我真的希望它是这样的:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多