重置jQuery Mobile的值 [英] Reset values from jQuery Mobile

查看:177
本文介绍了重置jQuery Mobile的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重置我的网页的字段元素的所有值。元素是:输入,选择(组合框),复选框和单选组。
搜索找到以下代码:

I need to reset all the values ​​of field elements of my page. The elements are: inputs, selects (combobox), checkbox and radio group. Searching found the following code:

$("*").attr('value', '');
$("input[type='checkbox']").attr("checked",false); 

$('select').each(function() {
    if($(this).children().length > 0) {
        $($(this).children()[0]).attr('selected', 'selected');
        $(this).change();
    }
});

输入和复选框可以使用此代码,但其他组件提供测试代码的问题。无线电组需要或采取任何种类的选择或至少选择第一。组合框用此代码重置,但是当尝试选择一个新值时,它不会存储您的值。

Inputs and checkbox are ok with this code, but the other components present problems with the codes tested. The radio group needed or take any kind of selection or at least select the first. The combobox resets with this code but when trying to select a new value it is not storing your value.

谢谢!

推荐答案

非文本输入需要刷新。下面是一个这样做的示例:

The non textual inputs need to be refreshed. Here's an example of doing so:

//reset text input values, then refresh slider widgets
$(".ui-input-text").val('').filter('.ui-slider-input').slider('refresh');

//reset checkboxes and radio inputs, then refresh them
$(".ui-checkbox input[type='checkbox'], .ui-radio input[type='radio']").prop("checked", false).checkboxradio("refresh"); 

//reset all select menus and then refresh them
$('.ui-select select').val('').selectmenu('refresh');
return false;

这是一个演示: http://jsfiddle.net/MLewd/1/

这篇关于重置jQuery Mobile的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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