如何在JQuery中选择给定div中的所有textarea框?(禁用/要求全部)

fmd*_*mdx 1 forms jquery textarea

我有一个项目,当选中一个复选框时,在表单中显示DIV,并且在该DIV中是一个可以无限添加文本区域的脚本.

我想要的是如果创建了这些文本区域,我想禁用所有这些文本区域,并且如果取消选择过度拱形复选框,则不要求它们.

编辑:我特定于给定DIV中的textareas的原因是因为我在表单上的其他地方有文本区域!

那么,我如何选择给定DIV中的所有文本框?或者,通过名字?(所有这些都在给定的类上(因为它们都是needb1_3 []数组的一部分)).我找到了一些代码/线程/答案来选择输入框,无线电,复选框,但从不发送文本区域.

在此先感谢您的帮助.

jsfiddle:http://jsfiddle.net/fmdx/rNqwc/1/

HTML:

<div>
    <input id="needb1-3customcheck" type="checkbox" class="schedb1checkboxes[]" data-     select="#needb1-3custom">Need Custom?
</div>
<div id="needb1-3custom" style="display:none; padding-left:40px;">
    <div id="customb1_3" style="padding-left:40px;">
        <textarea id="needb1_3_1" placeholder="Six Foot Utility..." name="needb1_3[]" required>
        </textarea>
    </div><!-- Ending Custom Div -->
    <div style="padding-left:40px;"><a id="add_b1_3" href="#"><span>Add Exception</span></a></div>
</div>
Run Code Online (Sandbox Code Playgroud)

JQuery的:

var b1_3customcounter = 1;
$(function () {
    $('a#add_b1_3').click(function () {
    b1_3customcounter += 1;
        $('#customb1_3').append(
        '<div><textarea id="need_b1_3_' + b1_3customcounter + '" placeholder="Six Foot Utility..." name="needb1_3[]' + '" required></textarea><a class="remove" href="#">Remove</a></div>');                                 
        event.preventDefault();
    });
});

$(document).on('click', '.remove', function(){
var $this = $(this);
$(this).closest('div').remove();
event.preventDefault();
});

$('#needb1-3customcheck').click(function(){
    var collapse_content_selector = $(this).attr('data-select');                    

    $(collapse_content_selector).toggle(function(){
      if($(this).css('display')=='none'){
                    //Do this while the section is hidden
        $('#needb1_3_1').prop('required', false);
}else{
        //Do this while the section is visible
        $('#needb1_3_1').prop('required', true);
      }
    });
  });
Run Code Online (Sandbox Code Playgroud)

Sam*_*amV 6

根据元素名称而不是类或id选择textareas.

尝试:

$('#form textarea').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)

这将适用于其他的,如selectinput.

因此,要禁用div中的所有textareas,请#needb1-3custom尝试:

$('#needb1-3custom textarea').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)