jQuery Uniform Checkbox 不(取消)选中

2023-10-20前端开发问题
1

本文介绍了jQuery Uniform Checkbox 不(取消)选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 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

推荐答案

简单的解决方案

这是因为如果您需要更改值,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 不(取消)选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Fatal error: Call to a member function fetch_assoc() on a no
业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass...
2024-12-13 前端开发问题
136

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui树状组件tree怎么默认勾选?
在layui树状组件tree中,勾选问题可以通过以下方法解决: 通过tree的oncheck事件来监听勾选操作,然后根据勾选状态进行相应的处理。例如: tree.on('check', function(obj) { // 获取勾选状态 var isChecked = obj.checked; // 获取当前节点数据 var data =...
2024-11-09 前端开发问题
372

layui laydate日期时间范围,时间默认设定为23:59:59
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24 前端开发问题
279

layui中表单会自动刷新的问题
layui中表单会自动刷新的问题,因为用到layui的表单,遇到了刷新的问题所以记录一下: script layui.use(['jquery','form','layer'], function(){ var $ = layui.jquery, layer=layui.layer, form = layui.form; form.on('submit(tijiao)', function(data){ a...
2024-10-23 前端开发问题
262