Reset values from jQuery Mobile

萝らか妹 提交于 2019-12-04 04:47:58

问题


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.

Thanks!


回答1:


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;

Here is a demo: http://jsfiddle.net/MLewd/1/



来源:https://stackoverflow.com/questions/13765644/reset-values-from-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!