Jquery selector input[type=text]')

前端 未结 4 1130
不思量自难忘°
不思量自难忘° 2020-12-23 03:01

I wrote a code that basically selects all input type=text element like this:

$(\'.sys input[type=text]\').each(function () {}

4条回答
  •  甜味超标
    2020-12-23 03:16

    If you have multiple inputs as text in a form or a table that you need to iterate through, I did this:

    var $list = $("#tableOrForm :input[type='text']");
    
    $list.each(function(){
        // Go on with your code.
    });
    

    What I did was I checked each input to see if the type is set to "text", then it'll grab that element and store it in the jQuery list. Then, it would iterate through that list. You can set a temp variable for the current iteration like this:

    var $currentItem = $(this);
    

    This will set the current item to the current iteration of your for each loop. Then you can do whatever you want with the temp variable.

    Hope this helps anyone!

提交回复
热议问题