forms - 从 jQuery Mobile 重置值

标签 forms input checkbox jquery-mobile radio-button

我需要重置我的页面的所有字段元素的值。这些元素是:输入、选择(组合框)、复选框和单选组。 搜索发现如下代码:

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

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

此代码的输入和复选框正常,但其他组件在测试的代码中存在问题。 radio 组需要或采取任何类型的选择或至少选择第一个。组合框使用此代码重置,但当尝试选择新值时,它不会存储您的值。

谢谢!

最佳答案

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

//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/

关于forms - 从 jQuery Mobile 重置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13765644/

相关文章:

html - 一行输入文字提交

javascript复制输入文件并获取完整文件路径

php - 如何禁用该复选框并使用 php 更新数据库

css - 当我将它转换到我的 CMS 时,为什么 CSS 排序(使用复选框 hack)不起作用?

ruby-on-rails - 选择所有复选框

javascript - 为什么我的表单不验证字段?

Javascript,如何提交表单,然后关闭当前窗口?

javascript - 如何用jQuery打开一个新窗口并访问新窗口中的元素?

c - 如何在for循环中使用scanf

c# - 如何使用 checkedit gridcontrol devexpress 选择行?