开发者

jQuery - How to use Each() Method to loop through and alter all checked boxes on a page load

I'm loading a web page that has a series of 20+ checkboxes. The page is being loaded with data from a database, so that some of the checkboxes will be checked, and textareas connected to those checkboxes will have some text in them. What I think I want to do is: 1) iterate through all the chekboxes and find the ones that are checked 2) then modify the 'disabled' attribute and css properties of each related textarea

Each checkbox has a unique ID (for example, specA01, specA02, specA03, etc...) and each textarea has a unique but related ID (for example, specA01summ, specA02summ, specA03summ, etc...)

I have this code that I modified from another line on the same page, but I know I'm misunderstanding some basic principle here... probably has to do with the ".this" line...

    $("input[type=checkbox][checked]").each(
    开发者_Python百科        function() {
                var checkBoxId = $(this).attr('id');
                $('#' + checkBoxId + 'summ').removeAttr("disabled");
                $('#' + checkBoxId + 'summ').css({'background-color' : '#ffffff', 'color' : '#000000', 'border-color' : '#696FA3', 'height' : '10em'});
                $('#' + checkBoxId + 'summRequired').css("display", "block");

            });

Essentially, in this code, I'm trying to loop through all checked checkboxes, get each of their ID's in a variable called 'checkBoxID', and then modify the textarea element with the ID of '#' + checkBoxId + 'summ' .Any help or guidance you can provide is very much appreciated. Sorry for my blatant ignorance. I'm still learning programming and jQuery.


$(":checkbox:checked").each(function(o){
  var chkID = $(this).attr("id");
  $("#"+chkID+"summ").removeAttr("disabled");
  /* ... */
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜