input清空和重置select下拉框


背景

一般頁面搜索條件都會有input輸入框和select選擇框,同時頁面上都會有重置reset按鈕,這時就需要清空input和重置select


 

實現

清空input

清空單個input:

$("inputId").val("");

清空div下所有input:

$("#divId input").val("");

 

重置select

重置單個select:

 

    $("#selectId option").removeAttr("selected");//選擇出所有option,然后刪除selected屬性

或者

$("#selectId").find("option:selected").removeAttr("selected");//選擇出所有被選擇的option,刪除其selected屬性

 

重置div下多個select:

$("#divId select").each(function ()
{
    $(this).find("option:selected").removeAttr("selected");
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM