通过JQuery更改表单标签上的标签

时间:2016-08-08 10:29:50

标签: javascript jquery html

我搜索了jquery更改标签,尽管有很多答案与我的问题无关。我想将标签更改为包含链接的其他内容。我似乎无法让它工作!我把JS放在代码的头部位置,但没有运气,甚至使用JSFiddle,请参阅下文。我做错了什么?

的jsfiddle https://jsfiddle.net/14tx86j5/

HTML

    <input name="input_147.1" value="I agree to Veryappt’s Terms of Service" id="choice_3_147_1" type="checkbox">
    <label for="choice_3_147_1" id="label_3_147_1">I agree to Companies Terms of Service</label>

Jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
 jQuery.noConflict();
   jQuery(document).ready(function($) {

      $("#label_3_147_1 label").html('You also agree to our <a href="http://www.google.com/accounts/TOS" name="terms" target="_blank">Privacy Policy</a>, which describes how we process your information. <a href="https://support.google.com/accounts/answer/1733224?hl=en-GB" name="terms" target="_blank">Learn More</a> about why we ask for this information.');

   });
 </script>

3 个答案:

答案 0 :(得分:1)

你有错误的选择器来定位标签元素。您使用的选择器在标识为label_3_147_1的元素内查找标签元素。你需要使用:

$("#label_3_147_1")

答案 1 :(得分:0)

适合我。 您需要包含JS库

   $('#label_3_147_1').html('You also agree to our <a href="http://www.google.com/accounts/TOS" name="terms" target="_blank">Privacy Policy</a>, which describes how we process your information. <a href="https://support.google.com/accounts/answer/1733224?hl=en-GB" name="terms" target="_blank">Learn More</a> about why we ask for this information.');

   });

Fiddle

答案 2 :(得分:0)

您只能使用类似ID的ID:

$(&#34;#label_3_147_1&#34;)。html(&#39;把你的HTML放到这里&#39;);