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

Change label on form label via JQuery

本文关键字:标签 表单 JQuery 改变 通过      更新时间:2023-09-26

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

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

    <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>

你有错误的选择器目标标签元素。您使用的选择器在id为label_3_147_1的元素中查找标签元素。您需要使用:

$("#label_3_147_1")

适合我。你需要包含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.');
   });

小提琴

你可以只使用标签的id像这样:

$ (" # label_3_147_1 ") . html(这里把你的html);