[英]Why do I need to click to change focus for element CSS to update
I have a checkbox on my page that I've created custom error control CSS attributes for (similar to has-error & has-success): 我的页面上有一个复选框,我为此创建了自定义错误控制CSS属性(类似于has-error和has-success):
.has-checkbox-error {
outline-width: 1px;
outline-style: solid;
outline-color: #a94442 !important;
}
.has-checkbox-success {
outline-width: 1px;
outline-style: solid;
outline-color: #3c763d !important;
}
Here is the HTML for the actual element on the page: 这是页面上实际元素的HTML:
<div class="checkbox" id="div_terms">
<div id="input_terms">
<input type="checkbox" class="form-control" id="terms" name="terms" />
<p id="terms_p">By checking this box, you agree to the <a id="terms_a" href-"https://www.twfbl.com/joomla30/league-info/league-rules" target="_blank">League Rules</a> and note that they are subject
to change at any time. You agree to abide by all league rules.</p>
</div>
</div>
When the checkbox value is changed, it runs the following jQuery: 复选框值更改后,它将运行以下jQuery:
jQuery("#terms").on("change", function() {
if(jQuery("#terms").prop("checked")) {
jQuery("#terms").removeClass("has-checkbox-success has-checkbox-error has-feedback");
jQuery("#terms").addClass("has-checkbox-success has-feedback");
jQuery("#input_terms").prop("title", "");
} else {
jQuery("#terms").removeClass("has-checkbox-success has-checkbox-error has-feedback");
jQuery("#terms").addClass("has-checkbox-error has-feedback");
jQuery("#input_terms").prop("title", "Required. You MUST agree to terms in order to join the league.");
}
})
However, when it executes on the page the colorization does not change until you click somewhere else on the page? 但是,当它在页面上执行时,着色不会改变,除非您单击页面上的其他位置? See https://www.twfbl.com/joomla30/registration-form to see what I mean.
请参阅https://www.twfbl.com/joomla30/registration-form以了解我的意思。
I tried to dynamically change focus in the code (using jQuery["#terms_p"}.focus()), but it did not react the same as clicking on the page. 我试图动态更改代码中的焦点(使用jQuery [“#terms_p”}。focus()),但是它的效果与单击页面不同。
Any insight would be greatly appreciated. 任何见识将不胜感激。
jQuery("#terms").on("change", function() { if(jQuery("#terms").prop("checked")) { jQuery("#terms").removeClass("has-checkbox-success has-checkbox-error has-feedback"); jQuery("#terms").addClass("has-checkbox-success has-feedback"); jQuery("#input_terms").prop("title", ""); } else { jQuery("#terms").removeClass("has-checkbox-success has-checkbox-error has-feedback"); jQuery("#terms").addClass("has-checkbox-error has-feedback"); jQuery("#input_terms").prop("title", "Required. You MUST agree to terms in order to join the league."); } })
.has-checkbox-error { outline-width: 1px; outline-style: solid; outline-color: #a94442 !important; } .has-checkbox-success { outline-width: 1px; outline-style: solid; outline-color: #3c763d !important; } .has-checkbox-success:focus { outline-width: 1px; outline-style: solid; outline-color: #ffcc00 !important; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="checkbox" id="div_terms"> <div id="input_terms"> <input type="checkbox" class="form-control" id="terms" name="terms" /> <p id="terms_p">By checking this box, you agree to the <a id="terms_a" href-"https://www.twfbl.com/joomla30/league-info/league-rules" target="_blank">League Rules</a> and note that they are subject to change at any time. You agree to abide by all league rules.</p> </div> </div>
You shouldn't focus the checkbox as you can see, if you remove .has-checkbox-success:focus from the code above, it works fine. 如您所见,您不应该关注复选框,如果您从上面的代码中删除了.has-checkbox-success:focus ,它将正常工作。
The border of the checkbox in the page you posted is white or maybe set to none, check your css rules. 您发布的页面中复选框的边框为白色或可能设置为无,请检查CSS规则。
EDIT: 编辑:
This is the css that's giving you trouble. 这就是给您带来麻烦的CSS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.