将标签转换为href [英] Converting label to href

查看:69
本文介绍了将标签转换为href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些看起来像这样的html:

I have some html that looks like this:

<div class="generated">
<p><label for="id_group">Group</label> <select name="group" id=" id_group" tabindex="1">
<option value="" selected="selected"></option>
<option value="1">12S</option>
<option value="2">13S</option>
<option value="3">22SOI</option>
</select></p>
</div>

我想将标签"Group"设为href.我该如何使用jQuery?

I want to make the label 'Group' to be a href. How can I do that with jQuery?

推荐答案

尝试:

var html = $('label[for="id_group"]').html();
$('label[for="id_group"]').html('<a href="my_link.html">'+html+'</a>');

注意:这不会将label替换为a,但会将链接插入label元素内(因此您仍然可以保持表单的label-input关系).

NOTE: This will not replace the label with a a, but it'll insert the link inside the label element (so you can still keep your form's label-input relations).

这篇关于将标签转换为href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆