我搜索了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>
答案 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.');
});
答案 2 :(得分:0)
您只能使用类似ID的ID:
$(&#34;#label_3_147_1&#34;)。html(&#39;把你的HTML放到这里&#39;);