2016-08-01 10 views
0

私は動作するコードを取得するのに苦労していますが、私はjqueryの人ではありませんので、私に同行してください。セレクタから要素を取り除く方法

I have an outer DIV ($scope)。それはすべての種類の入力を含んでいます。

各入力タイプのすべてのエントリを見つけ、それらをフィルタリングして値を持つものを取得します。これらは$エントリに格納されます。

$inputs contains all the inputs regardless of type or status. 

私がしようとしているのは、違いを残すためにremove $entries from $inputsです。

これはうまくいかず、現時点ではエラーが発生していないため、何も進んでいません。

私の最初の考えは、jqueryは、実際のオブジェクトではなくインデックスを保持しているため、あるリストの要素を他のリストと一致させることができないということです。これは完全に間違っている可能性があります(1行目を参照してください)。

どちらの方法でも、私はすべての要素を取得し、それらを2ビットに分割する方法を見つける必要があります。

すべてのお役に立ちました。

function inputLoaded(isPostback) { 
      if (typeof Page_Validators !== "undefined") { 

$scope = $(".active-step:first"); 
       $inputs = $scope.find(inputs); 
      $cb = $scope.find(checkboxes).filter(":checked"); 
      $rb = $scope.find(radios).filter(":checked"); 
      $sb = $scope.find(selects).filter(function() { return $(this).val() !== "None"; }); 
      $ta = $scope.find(textareas).filter(function() { return $(this).val(); }); 
      $tb = $scope.find(textboxes).filter(function() { return $(this).val(); }); 
      $entries = $cb.add($rb).add($sb).add($ta).add($tb); 

      // Do things with $entries here 

      // Get elements that have not got entries 
      $el = $inputs.remove($entries); 

     } 
    } 
+0

'$ inputs.filter(input =>!$ entries.contains(input))'のように見えますか? – gcampbell

+0

@gcampbell - なぜOPがそれを使用していないときにes6を選択するのですか? – evolutionxbox

+0

'$ input.not($ entries)'はもっと簡単になります。 –

答えて

0

not()方法は、その内容あなたはそれが適用jQueryオブジェクトから除外されるjQueryオブジェクトを取ることができます。

// Get elements, excluding entries. 
$el = $input.not($entries); 
0

私はあなたがセレクタを書くのを忘れて推測:

function inputLoaded(isPostback) { 
    if (typeof Page_Validators !== "undefined") { 

     $scope = $(".active-step:first"); 
     $inputs = $scope.find("input, select, textarea"); 
     $cb = $scope.find(":checkbox").filter(":checked"); 
     $rb = $scope.find(":radio").filter(":checked"); 
     $sb = $scope.find("select").filter(function() { 
      return $(this).val() !== "None"; }); 
     $ta = $scope.find("textarea").filter(function() { 
      return $(this).val(); }); 
     $tb = $scope.find(":text").filter(function() { 
      return $(this).val(); }); 
     $entries = $cb.add($rb).add($sb).add($ta).add($tb); 

     // Do things with $entries here 

     // Get elements that have not got entries 
     $el = $inputs.remove($entries); 

    } 
} 
関連する問題