2016-08-08 43 views
0

我搜索了jquery更改标签,虽然有很多答案他们不涉及我的问题。我想将标签更改为包含链接的其他内容。我似乎无法得到它的工作!我把JS放在代码的头部位置,但没有运气,甚至使用JSFiddle,请参阅下面的内容。我究竟做错了什么?通过JQuery更改表单标签上的标签

的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> 
+0

你需要包括jquery自由https://code.jquery.com/jquery-1.12.3.min.js –

+0

具有相同ID的两个元素总是会给你这些错误 –

+0

除了现在发布的答案,我想知道你为什么要做这件事? 你不能只修改html? :P – twicejr

回答

1

你错了选择目标标签元素。您使用的选择器查找ID为label_3_147_1的元素内的标签元素。您需要使用:

$("#label_3_147_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

0

只能使用的标签类似的东西ID:

$( “#label_3_147_1”)HTML('把你的html here');