javascript - Change value of label element inserting href inside
问题描述
I have this element:
<li class="choice-1 depth-1"><input type="checkbox" id="wpforms-1028-field_3_1" name="wpforms[fields][3][]" value="Acepto la política de privacidad" required ><label class="wpforms-field-label-inline" for="wpforms-1028-field_3_1">Acepto la política de privacidad</label></li>
I want to change this text: Acepto la política de privacidad
to this: Acepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>
I have tried this code:
document.getElementById("wpforms-1028-field_3_1").value="Acepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>"
But it doesn't work because it seem I am not inside the "label" element.
解决方案
您可以使用文档查询选择器
document.querySelector(".wpforms-field-label-inline").innerHTML = "cepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>";
推荐阅读
- java - 如何识别我的 AES 加密是 128 还是 256?
- r - 为每个组添加固定数量的行,其值基于另一列
- android - 在 Android 应用程序中启动 Google Firebase 分析实例的最佳方式是什么?
- sharepoint - SharePoint Online 列表:如何对查阅列的下拉列表选项进行排序?
- python - python flatten array 数组,为什么 funtools 比较慢?
- c# - 如何使用带有外部表属性的 txtbox.DataBindings?
- node.js - 单击登录后,页面会重新加载,然后我会返回登录弹出窗口。我正在使用 Nodejs - Auth0 - Heroku
- git - GitLab 克隆错误 RPC 失败;curl 56 请求的 URL 返回错误:401
- angular - 从回调函数访问不同命名空间中的属性和方法
- excel - 如何根据开始和长度动态填充单元格