jQuery 统一复选框不(取消)检查 [英] jQuery Uniform Checkbox does not (un)check

查看:21
本文介绍了jQuery 统一复选框不(取消)检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 以便所有操作(即 clickfocusblur 等)都在 .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

推荐答案

SIMPLE SOLUTION

这是因为 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 统一复选框不(取消)检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆