簡體   English   中英

如何找到所有帶有值的輸入

[英]How to find all inputs with values

目的是列出頁面上所有輸入的所有值,而不列出沒有值的輸入,這是兩個問題:

$(":input").not("[id*=a_prefix_]").map(function() 
    { 
        var value = this.val(); 
        if( value ) console.log(this.id + ":=" + value ); 
    }
);
  1. this.val()存在問題,出現錯誤“對象不支持屬性或方法'val'”,解決方案是什么?
  2. 如何移動檢查以查看實際選擇中是否包含值,以便地圖僅獲取帶有值的輸入?
var valueArray = $(":input")
    // filter these things out, whatever they are
    .not("[id*=a_prefix_]")
    // filter only the elements that have a value
    .filter(function(){ return this.value.trim(); })
    // map the values
    .map(function(){ return {[this.id]: this.value}; })
    // turn the results into a real array, not a jQuery object of the values
    .get();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM