[英]javascript to add aria attribute
I'm trying to add aria-required="true" attributes to some form elements from ninja forms in wordpress. 我正在尝试将aria-required =“ true”属性添加到wordpress中忍者表单的某些表单元素中。 I'm using a header/footer script inject plugin.
我正在使用页眉/页脚脚本注入插件。 But I can't seem to get my code to actually work.
但是我似乎无法使我的代码真正起作用。 Any help would be greatly appreciated!
任何帮助将不胜感激!
http://champion.magnet.today/contact/ http://champion.magnet.today/contact/
<script> function codeAddress() { var x = document.getElementsByClassName("nf-element"); var i; for (i = 0; i < x.length; i++) { x[i].addAttribute("aria-required", "true"); } window.onload = codeAddress } </script>
<div class="nf-field-element"> <input id="nf-field-17" name="nf-field-17" class="ninja-forms-field nf-element" type="text" value="" placeholder="First Name"> </div>
try replacing x[i].addAttribute("aria-required", "true");
尝试替换
x[i].addAttribute("aria-required", "true");
with x[i].setAttribute("aria-required", "true");
与
x[i].setAttribute("aria-required", "true");
You need to use setAttribute . 您需要使用setAttribute 。 Also window.load should be outside the
codeAddress
function 另外window.load应该在
codeAddress
函数之外
function codeAddress() { var x = document.getElementsByClassName("nf-element"); var i; for (i = 0; i < x.length; i++) { console.log(x[i]) x[i].setAttribute("aria-required", "true"); } } window.onload = codeAddress
<div class="nf-field-element"> <input id="nf-field-17" name="nf-field-17" class="ninja-forms-field nf-element" type="text" value="" placeholder="First Name"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.