如何禁用titlediv_1274837 div中的所有输入,选择文本区域

时间:2019-06-20 16:50:33

标签: jquery

我有一个应该使titlediv_1274837 div内的所有输入,选择和textarea禁用的函数,但是当我运行该函数时它不起作用。我尝试了单个jquery语句,也尝试了每个循环。它没有使任何输入,选择,textarea禁用。我要粘贴浏览器生成的HTML。

$("#titlediv_1274837 :input").attr("disabled", true);

$("#titlediv_1274837 :input").each(function() {
  $(this).attr("readonly", false);
});

$("#titlediv_1274837").find("input,button,textarea,select").attr("disabled", "disabled");
<!doctype html>
<html lang="en">

<head>

  <LINK REL="stylesheet" TYPE="text/css" HREF="/jquery/css/themes/base/jquery-ui.css?v=201805.06">
  <SCRIPT type="text/javascript" src="/jquery/jquery.js?v=201805.06"></SCRIPT>
  <SCRIPT type="text/javascript" src="/jquery/jquery-ui.min.js?v=201805.06"></SCRIPT>
  <script type="text/javascript">
  </script>
</head>

<body id="v-body">
  <div id="notesframe_div">
    <iframe src="/s_viewnotes_vert.jsp?appid=102950&objecttype=100&objectid=1231692&nnote=1&initload=1" id="notes_frame"></iframe>
  </div>
  <div id="v-container" class="v-container" ng-app="app" ng-controller="controller">
    <div id="v-content" class="v-content">
      <div style="clear:both"></div>
      <form action="app_editopportunity.jsp?nextlevel=1&" method="post" onsubmit="return sb(this);" id="form1">
        <div id="f-container">
          <div class=Container>
            <div id='cfdiv_1' style='visibility:hidden;display:none'>
              <div id='titlediv_1274837'>
                <table width=100% border=0 cellpadding=0 cellspacing=0 class=Form>
                  <tr>
                    <th id="cf_1274838_th"><span class='Required' title='Required'><label for='cf_1274838'>Subsequent Referrals # 1 Service Requested</label>:</span></th>
                    <td id="cf_1274838_td" name="td2">
                      <input type="hidden" name="cfdefault_1274838" id="cfdefault_1274838" value="- Select One -" />
                      <select class="Large" style="" name="cf_1274838" id="cf_1274838" aria-label="Subsequent Referrals # 1 Service Requested">
                        <Option Value="- Select One -">- Select One -</Option>
                        <Option Value="IME" selected>IME</Option>
                      </select>
                      <input type="hidden" id="sec_cf_1274838">
                    </td>
                    <th id="cf_1274839_th"><span class='Required' title='Required'><label for='cf_1274839'>Subsequent Referrals # 1 IME Questions Set</label>:</span></th>
                    <td id="cf_1274839_td" name="td2">
                      <input type="hidden" value="" name="cf_1274839" id="cf_1274839">
                      <div class="ssCheckBoxContainer">
                        <table id="cf_1274839_div" cellspacing="0" cellpadding="0" aria-label="Subsequent Referrals # 1 IME Questions Set">
                          <tr>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274839 id=cf_1274839_0 value="Neuropsychological"><label for='cf_1274839_0'>Neuropsychological</label><input type="hidden" id="sec_cf_1274839" name="sec_cf_1274839" value="d0dNaFtpbhplbmIBdmVQVF1XXAUZdQkNC1VVaTECDwUOMw8~"></td>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274839 id=cf_1274839_1 value="Psychiatric"><label for='cf_1274839_1'>Psychiatric</label><input type="hidden" id="sec_cf_1274839" name="sec_cf_1274839" value="d0dNaFtpbhplbmIBdmVQVF1XXAUZdQkNC1VVaTECDwUOMw8~"></td>
                          </tr>
                        </table>
                      </div>
                    </td>
                  </tr>
                  <tr id="cf_1274840_label_tr">
                    <th id="cf_1274840_th" valign=top class="FormTop" colspan=4><label for='cf_1274840'>Subsequent Referrals # 1 Referral Questions To The Assessor</label></th>
                  </tr>
                  <tr id="cf_1274840_tr">
                    <td id="cf_1274840_td" colspan=4 class="Form FormTop"><textarea class="textcontainer Hundred" cols='' rows='25' id="cf_1274840" name="cf_1274840" aria-label="Subsequent Referrals # 1 Referral Questions To The Assessor">
                                    </textarea><input type="hidden" id="sec_cf_1274840" name="sec_cf_1274840" value="SWJedmZ5ewIGU1hOXll8SU4aDwpXUFh@C1VVaTECDwUOBwY~">
                    </td>
                  </tr>
                  <tr>
                    <th id="cf_1274841_th"><label for='cf_1274841'>Subsequent Referrals # 1 Specialty</label>:</th>
                    <td id="cf_1274841_td" name="td2">
                      <input type="hidden" name="cfdefault_1274841" id="cfdefault_1274841" value="- Select One -" />
                      <select class="Large" style="" name="cf_1274841" id="cf_1274841" aria-label="Subsequent Referrals # 1 Specialty">
                        <Option Value="- Select One -">- Select One -</Option>
                        <Option Value="Anesthesiologist" selected>Anesthesiologist</Option>
                      </select>
                      <input type="hidden" id="sec_cf_1274841" name="sec_cf_1274841" value="SwdxAmdCAmkGcnBZW3RCfXRVcmFbeFhfC1VVaTECDwUOBwc~">
                    </td>
                    <th id="cf_1274842_th"><label for='cf_1274842'>Subsequent Referrals # 1 Imaging Service Category</label>:</th>
                    <td id="cf_1274842_td" name="td2">
                      <input type="hidden" value="" name="cf_1274842" id="cf_1274842">
                      <div class="ssCheckBoxContainer">
                        <table id="cf_1274842_div" cellspacing="0" cellpadding="0" aria-label="Subsequent Referrals # 1 Imaging Service Category">
                          <tr>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274842 id=cf_1274842_0 value="MRI Exam"><label for='cf_1274842_0'>MRI Exam</label><input type="hidden" id="sec_cf_1274842" name="sec_cf_1274842" value="YUpNVnd9YEd@Wl9GfhkJQUxfXQF3ZAFgC1VVaTECDwUOBwQ~"></td>
                          </tr>
                        </table>
                      </div>
                    </td>
                  </tr>
                </table>
              </div>
              <!--Label-->
              <!--no caption-->
              <!--id=1274848-->
              <div class='titlediv' name='titlediv_1274848' id='titlediv_1274848'>
                <table width=100% border=0 cellpadding=0 cellspacing=0 class=Form>
                  <script language='javascript'>
                    // Browser script cf_1274849                                 

                    function FreezeSubsequentReferralsInformation() {
                      alert('a');
                      $('#titlediv_1274837').find("input,button,textarea,select").each(function(key, value) {
                        $(value).eq(0).attr('disabled', 'disabled');
                        console.log($($(value)[0]).attr());
                      });
                    }

                    $(document).ready(function() {
                      FreezeSubsequentReferralsInformation();
                    });
                  </script>
                </table>
                <table width="100%" border="0" cellpadding="0" cellspacing="0" cols="2"></table>
              </div>
            </div>
          </div>
        </div>
        <div id="listdiv">
        </div>
    </div>
  </div>
  <div id="v-footer">
    </table>
  </div>
  </form>
  </div>
  </div>
  <script type="text/javascript">
  </script>
</body>

</html>

1 个答案:

答案 0 :(得分:1)

您只需要使用$("#titlediv_1274837 :input").attr("disabled", true);

  $(document).ready(function(){
       $("#titlediv_1274837 :input").attr("disabled", true);
    });

这足以禁用您的控件

注意:在您的html中,您需要将其删除以显示表单

<div id='cfdiv_1' style='visibility:hidden;display:none'>

$(document).ready(function(){
   $("#titlediv_1274837 :input").attr("disabled", true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="app_editopportunity.jsp?nextlevel=1&" method="post" onsubmit="return sb(this);" id="form1">
        <div id="f-container">
          <div class=Container>
            <div id='cfdiv_1'>
              <div id='titlediv_1274837'>
                <table width=100% border=0 cellpadding=0 cellspacing=0 class=Form>
                  <tr>
                    <th id="cf_1274838_th"><span class='Required' title='Required'><label for='cf_1274838'>Subsequent Referrals # 1 Service Requested</label>:</span></th>
                    <td id="cf_1274838_td" name="td2">
                      <input type="hidden" name="cfdefault_1274838" id="cfdefault_1274838" value="- Select One -" />
                      <select class="Large" style="" name="cf_1274838" id="cf_1274838" aria-label="Subsequent Referrals # 1 Service Requested">
                        <Option Value="- Select One -">- Select One -</Option>
                        <Option Value="IME" selected>IME</Option>
                      </select>
                      <input type="hidden" id="sec_cf_1274838">
                    </td>
                    <th id="cf_1274839_th"><span class='Required' title='Required'><label for='cf_1274839'>Subsequent Referrals # 1 IME Questions Set</label>:</span></th>
                    <td id="cf_1274839_td" name="td2">
                      <input type="hidden" value="" name="cf_1274839" id="cf_1274839">
                      <div class="ssCheckBoxContainer">
                        <table id="cf_1274839_div" cellspacing="0" cellpadding="0" aria-label="Subsequent Referrals # 1 IME Questions Set">
                          <tr>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274839 id=cf_1274839_0 value="Neuropsychological"><label for='cf_1274839_0'>Neuropsychological</label><input type="hidden" id="sec_cf_1274839" name="sec_cf_1274839" value="d0dNaFtpbhplbmIBdmVQVF1XXAUZdQkNC1VVaTECDwUOMw8~"></td>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274839 id=cf_1274839_1 value="Psychiatric"><label for='cf_1274839_1'>Psychiatric</label><input type="hidden" id="sec_cf_1274839" name="sec_cf_1274839" value="d0dNaFtpbhplbmIBdmVQVF1XXAUZdQkNC1VVaTECDwUOMw8~"></td>
                          </tr>
                        </table>
                      </div>
                    </td>
                  </tr>
                  <tr id="cf_1274840_label_tr">
                    <th id="cf_1274840_th" valign=top class="FormTop" colspan=4><label for='cf_1274840'>Subsequent Referrals # 1 Referral Questions To The Assessor</label></th>
                  </tr>
                  <tr id="cf_1274840_tr">
                    <td id="cf_1274840_td" colspan=4 class="Form FormTop"><textarea class="textcontainer Hundred" cols='' rows='25' id="cf_1274840" name="cf_1274840" aria-label="Subsequent Referrals # 1 Referral Questions To The Assessor">
                                    </textarea><input type="hidden" id="sec_cf_1274840" name="sec_cf_1274840" value="SWJedmZ5ewIGU1hOXll8SU4aDwpXUFh@C1VVaTECDwUOBwY~">
                    </td>
                  </tr>
                  <tr>
                    <th id="cf_1274841_th"><label for='cf_1274841'>Subsequent Referrals # 1 Specialty</label>:</th>
                    <td id="cf_1274841_td" name="td2">
                      <input type="hidden" name="cfdefault_1274841" id="cfdefault_1274841" value="- Select One -" />
                      <select class="Large" style="" name="cf_1274841" id="cf_1274841" aria-label="Subsequent Referrals # 1 Specialty">
                        <Option Value="- Select One -">- Select One -</Option>
                        <Option Value="Anesthesiologist" selected>Anesthesiologist</Option>
                      </select>
                      <input type="hidden" id="sec_cf_1274841" name="sec_cf_1274841" value="SwdxAmdCAmkGcnBZW3RCfXRVcmFbeFhfC1VVaTECDwUOBwc~">
                    </td>
                    <th id="cf_1274842_th"><label for='cf_1274842'>Subsequent Referrals # 1 Imaging Service Category</label>:</th>
                    <td id="cf_1274842_td" name="td2">
                      <input type="hidden" value="" name="cf_1274842" id="cf_1274842">
                      <div class="ssCheckBoxContainer">
                        <table id="cf_1274842_div" cellspacing="0" cellpadding="0" aria-label="Subsequent Referrals # 1 Imaging Service Category">
                          <tr>
                            <td class="ssCheckBoxDiv"><input t2 checked type="checkbox" name=cf_1274842 id=cf_1274842_0 value="MRI Exam"><label for='cf_1274842_0'>MRI Exam</label><input type="hidden" id="sec_cf_1274842" name="sec_cf_1274842" value="YUpNVnd9YEd@Wl9GfhkJQUxfXQF3ZAFgC1VVaTECDwUOBwQ~"></td>
                          </tr>
                        </table>
                      </div>
                    </td>
                  </tr>
                </table>
              </div>
              <!--Label-->
              <!--no caption-->
              <!--id=1274848-->
              <div class='titlediv' name='titlediv_1274848' id='titlediv_1274848'>
                <table width=100% border=0 cellpadding=0 cellspacing=0 class=Form>
                 
                </table>
                <table width="100%" border="0" cellpadding="0" cellspacing="0" cols="2"></table>
              </div>
            </div>
          </div>
        </div>
        <div id="listdiv">
        </div>
    </div>
  </div>
  <div id="v-footer">
    </table>
  </div>
  </form>