风格验证

时间:2013-07-13 16:03:34

标签: javascript html css

我想知道是否可以将以下css转换为javascript?所以基本上它应该在onchange之后实现样式规则。

.appnitro input:required:valid, .appnitro textarea:required:valid {/* when a field is considered valid by the browser */
box-shadow: 0 0 5px #5cd053;
border-color: #28921f;
}


.appnitro input:focus:invalid, .appnitro textarea:focus:invalid { /* when a field is considere invalid by the browser */
box-shadow: 0 0 5px #5d45252;
border-color: #b03535;
}


<script>
function myFunction(){
??????
}
</script>


<form id="form_664184" class="appnitro"  method="post" action="">
    <input type="text" id="element_3"  name="element_2_1" value="Title" onchange="myFunction()" required />
</form>

1 个答案:

答案 0 :(得分:1)

是的,确实如此。这是应该如何:

yourElement.style.borderColor =  "#5cd053";
yourElement.style.boxShadow = "#5cd053";

按ID,类名或其他任何方式获取元素。