我需要使用 JavaScript 更改搜索表单占位符文本。
我有一个 ID 为 #mega-menu-item-search-6
的大型菜单搜索项。
在它的内部,我有一个带有类 .mk-searchform
和 id #searchform
的搜索表单。
我写了这个,但它不起作用。
document.getElementById("mega-menu-item-search-6").attr("placeholder", "Search product");
最佳答案
使用.setAttribute()
document.getElementById("mega-menu-item-search-6").setAttribute("placeholder", "Search product");
<form class="mk-searchform" id="searchform">
<input type="text" id="mega-menu-item-search-6">
</form>
关于javascript - 更改搜索表单占位符文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52437159/