我有这样的输入
<input type="text" class="form" name="_user_phone" id="_user_phone">我需要使用脚本将类更改为class="form phone“或class="phone”,因为我不能直接编辑代码,我下降到任何东西,JS,JQuery或任何其他解决方案,我看到了一些class=选项,但没有得到它的工作。
有什么建议吗?
发布于 2020-04-08 09:41:58
试一试
$("#_user_phone").attr('class','newClass');
发布于 2020-04-08 09:42:09
这个vanilla js,不需要任何库。
document.getElementById("_user_phone").className = "phone"; 发布于 2020-04-08 09:42:31
可以将setAttribute();与纯javascript一起使用
下面是一个示例:
document.getElementById('_user_phone').setAttribute("class", "phone"); //Change it!或者:
document.getElementById('_user_phone').className = "phone"; //Change it!或者在jQuery中使用attr():
$("#_user_phone").attr("class", "phone"); //Change it!要在jQuery中添加两个类,请使用addClass()
$("#_user_phone").addClass("form phone"); //Change it!https://stackoverflow.com/questions/61092032
复制相似问题