禁用/启用jQuery Mobile输入的常见方法是吗? [英] Is the a common way to disable/enable jQuery Mobile inputs?

查看:92
本文介绍了禁用/启用jQuery Mobile输入的常见方法是吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑表单,其中填充了jQuery Mobile输入,例如文本输入,滑块,复选框和按钮. 第一次显示表单时,将获取要编辑的内容(模型).

I have an edit form filled with jQuery Mobile inputs like Text-Inputs, Sliders, Checkboxes and Buttons. When the form first shows, the content (Model) to be edited is fetched.

在开始提取之前,我禁用了所有表单元素,以防止用户在提取内容(模型)时执行任何操作.只有取消按钮应该起作用. 已禁用"是指变灰且无法点击.

Before I start fetching, I disable all form elements to prevent the user from doing anything while the content (Model) is being fetched. Only the cancel button should work. "Disabled" means greyed out and not clickable for me.

表单加载完成后,我再次启用表单元素.

After the form has finished loading, I enable the form elements again.

当前,我只能通过自行选择每种输入类型来做到这一点.

Currently, I can only do this by selecting each input type by itself.

//These inputs work with .prop("disable", "true")
//#save is an <button type="submit">
var normalInputs = $("input[type='text'], #save");
//JQM converts <input type="range"> to this
var sliders = $("input[data-type='slider']");
var checkboxes = $("input[type='checkbox']");

normalInputs.prop("disabled", "true");
sliders.slider("disable").slider("refresh");
checkboxes.checkboxradio("disable").checkboxradio("refresh");

要启用,我什至必须调用slide()和checkboxradio()初始化方法,因为否则会出现错误(cannot call methods of xxx prior to initialization. attempted to call method enable)

For enabling, I even have to call the slider() and checkboxradio() initialization methods because I get an error otherwise (cannot call methods of xxx prior to initialization. attempted to call method enable)

是否存在一种仅使用一个选择器来正确禁用所有jQuery Mobile输入的方法?禁用/启用输入的常见方法?

Is there a method to correctly disable all of the jQuery Mobile inputs by using only one selector? A common way to disable/enable inputs?

推荐答案

您可以使用ui-state-disabled禁用任何元素. jQM将该类添加到具有disabled="disabled"属性的 disabled 中.

You can use ui-state-disabled class to disable any element. This class is added by jQM to disabled with disabled="disabled" attribute.

可以将其添加到form.

$("#form").addClass("ui-state-disabled");

按元素,即input,应将其添加到父div中,因为input在创建时会被包裹在div中.

By element, i.e. input, it should be added to parent div as input are wrapped in div upon creation.

$("input").closest("div").addClass("ui-state-disabled");

演示

Demo

这篇关于禁用/启用jQuery Mobile输入的常见方法是吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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