問題是,jQuery正在檢測頁面上存在的任何錯誤消息。將CSS樣式應用於包含錯誤消息的div
**看到的例子here
- 和我不想要的時候沒有消息應用的樣式。
代碼:
$(document).ready(function() {
if($('.CP_CF_Container > span.msg-error').length){
$('.vertical-input').addClass('checkbox-fld-error')
}
});
CSS:
.checkbox-fld-error{border:1px solid red}
.CP_CF_Container{width:50%;background-color:#eee;padding:5px;}
.msg-error{color:red}
HTML:
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
<span class="msg-error" >Error</span>
</div>
<br>
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
<span class="msg-error" >Error</span>
</div>
<br>
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
</div>
太謝謝你了! – namretiolnave