问题描述
我正在使用 jQuery Uniform 来设置输入/选择等样式.但是,该复选框已停止工作.我是 appending
从 ajax 调用发送的数据.加载后,我使用 $.uniform.update("input:checkbox")
更新新的 html.当尝试(取消)检查输入时,它只工作一次.如果我想再次(取消)检查它,它根本不会改变.
I am using jQuery Uniform to style inputs/selects etcs. However, the checkbox has stopped working. I am appending
data sent from an ajax call. Once it's loaded, I use $.uniform.update("input:checkbox")
to update the new html. When attempting to (un)check the input it works only once. If I want to (un)check it again, it doesn't change at all.
我尝试更改 Uniform Javascript 以便所有操作(即.click
、focus
、blur
等)在 .live
函数下.(即..live("click",
).这只会停止任何工作.
I've attempted changing the Uniform Javascript so that all the actions (ie. click
, focus
, blur
etc) are under the .live
function. (ie. .live("click",
). This just stops anything from working.
更新:
我通读了 Uniform JS 并发现了一个问题:
I've read through the Uniform JS entirely and discovered a problem:
if(!$(elem).attr("checked")){
//box was just unchecked, uncheck span
spanTag.removeClass(options.checkedClass);
}else{
//box was just checked, check span.
spanTag.addClass(options.checkedClass);
}
.attr("checked")
语法失败.它总是返回 false.为什么?我不知道.除此之外,它不会更新原始 input
以删除 checked
属性或设置 checked
属性.
The .attr("checked")
syntax fails. It will always return false. Why? I don't know. As well as this, it doesn't update the original input
to either remove the checked
attribute or to set the checked
attribute.
我浏览了官方网站,发现它没有更新复选框输入.所以不只是我xP
I've run through the official website and found it doesn't update the checkbox input. So it's not just me xP
我在谷歌上搜索了一下,发现了各种检查复选框是否被选中的方法,但是以下方法失败了:
I've Googled around a bit and found various methods for checking if a checkbox is checked however the following methods fail:
if ($(elem).attr("checked")) // The original.
if ($(elem).attr("checked") == true)
if ($(elem).is(":checked"))
if ($(elem).checked)
// and:
var check = $(elem).match(/checked=/);
if (check == null)
非常感谢您的指导~ :3
Words of guidance are very much appreciated~ :3
推荐答案
简单的解决方案
这是因为如果您需要更改值,UniformJs
要求您更新对统一元素的修改在表单上动态:
SIMPLE SOLUTION
This is because UniformJs
requires that you update your modification on uniform elements if you need to change values on the form dynamically:
$('#checkbox').prop('checked',true);
$.uniform.update();
编辑
如果您只想更新 #checkbox
:
$('#checkbox').prop('checked',true);
$.uniform.update('#checkbox');
这篇关于jQuery Uniform Checkbox 不(取消)选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!