亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

禁用并啟用使用 Java 腳本選擇值

禁用并啟用使用 Java 腳本選擇值

蝴蝶不菲 2022-09-29 17:30:25
我使用的是下面的代碼。如果我單擊“測試 1”或“測試 2”或選擇“全部”,將創建新行。如果執行類型為 Get,我需要禁用 DatatType 和預期集值列,如果我從“執行類型”中選擇“設置”,則應啟用“數據類型”和“預期集值”列。如何實現這一點?我正在Html.erb文件中使用此代碼。如何創建單獨的js方法?https://jsfiddle.net/bx5fa2vu/$("#all").on("click", function() {  if ($(this).is(":checked")) {    let boxes = $("#paramTable input[type='checkbox']").not(this).not(":checked");    boxes.each(function() {      $(this).click();    });  } else {    let boxes = $("#paramTable input[type='checkbox']:checked").not(this);    boxes.each(function() {      $(this).click();    });  }});$("#paramTable input[type='checkbox']:not(#all)").on("click", function() {  if ($(this).is(":checked")) {    let name = $(this).parent("td").next("td").next("td").text().trim();    let newname = name.split('.').join('');    let newrow = $("<tr>");    let newcell = $("<td> ");    let newSel=$("<select class='ExeType' name='ExeTypeValue'><option value='getData'>Get</option><option value='SetData'>Set</option></select>")    newcell.append(newSel);        newrow.append(newSel);    let newcell1 = $("<td> ");    let newinput = $("<input type='text' class='parameterName' name='" + newname + "' id='" + newname + "' value='" + name + "'/>");    newcell1.append(newinput);    newrow.append(newcell1); let newcells = $("<td><select class='parameterDscription' name='parameter_description'><option value=''>Select Data Type</option><option value='OCTET_STRING'>String</option><option value='INTEGER'>Integer</option><option value='INTEGER32'>Unsigned Integer</option><option value='IPADDRESS'>IP Address</option><option value='x'>Hex String</option></select></td><td><input type='text' class='expectedValue' name='expected_value'></td>");     newrow.append(newcells);    $("tbody.parameter_table").append(newrow);  }})
查看完整描述

1 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

你可以這樣做。請注意,最初不會禁用這些字段,因為在“執行類型選擇”字段中未選擇任何值。也許您想通過在選擇字段中添加帶有文本“選擇類型”的初始選項來使這一點更加清晰,就像您為數據類型選擇一樣。


$("#all").on("click", function() {

  if ($(this).is(":checked")) {

    let boxes = $("#paramTable input[type='checkbox']").not(this).not(":checked");

    boxes.each(function() {

      $(this).click();

    });

  } else {

    let boxes = $("#paramTable input[type='checkbox']:checked").not(this);

    boxes.each(function() {

      $(this).click();

    });

  }

});




$("#paramTable input[type='checkbox']:not(#all)").on("click", function() {

  if ($(this).is(":checked")) {

    let name = $(this).parent("td").next("td").next("td").text().trim();

    let newname = name.split('.').join('');

    let newrow = $("<tr>");

    let newcell = $("<td> ");

    let newSel = $("<select class='ExeType' name='ExeTypeValue'><option value='getData'>Get</option><option value='SetData'>Set</option></select>")

    newcell.append(newSel);

    newrow.append(newSel);

    let newcell1 = $("<td> ");


    let newinput = $("<input type='text' class='parameterName' name='" + newname + "' id='" + newname + "' value='" + name + "'/>");

    newcell1.append(newinput);


    newrow.append(newcell1);

    let newcells = $("<td><select class='parameterDscription' name='parameter_description'><option value=''>Select Data Type</option><option value='OCTET_STRING'>String</option><option value='INTEGER'>Integer</option><option value='INTEGER32'>Unsigned Integer</option><option value='IPADDRESS'>IP Address</option><option value='x'>Hex String</option></select></td><td><input type='text' class='expectedValue' name='expected_value'></td>");

    newrow.append(newcells);

    $("tbody.parameter_table").append(newrow);

  } else {

    let name = $(this).parent("td").next("td").next("td").text();

    let newname = name.split('.').join('');

    console.log("newname: " + newname)

    $("#addParamTable").find("#" + newname).closest("tr").remove();

    $("#all").prop("checked", false);

  }

})


$(document).on("change", ".ExeType", function() {

  let type = $(this).val();

  if (type === "getData") {

    $(this).closest("tr").find(".parameterDscription").attr("disabled", "disabled");

    $(this).closest("tr").find(".expectedValue").attr("disabled", "disabled");

  } else {


    $(this).closest("tr").find(".parameterDscription").removeAttr("disabled");

    $(this).closest("tr").find(".expectedValue").removeAttr("disabled");


  }

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table id="paramTable">

  <tr>

    <td><input type="checkbox" id="all" /></td>

    <td>Select all</td>

    <td></td>

  </tr>

  <tr>

    <td><input type="checkbox" /></td>

    <td>Testing 1</td>

    <td>1.2.3.4.5</td>

  </tr>

  <tr>

    <td><input type="checkbox" /></td>

    <td>Testing 2</td>

    <td>.1.3.4.5.8</td>

  </tr>

</table>

<div class="tab-content">

  <div id="protocol" class="tab-pane fade in active">

    <div class="span3 border-0" style="overflow: scroll">

      <table id="addParamTable" class="table table-bordered">

        <thead>

          <tr class="info">

                      <th>Excution Type</th>


            <th>Parameter Name</th>

            <th>Data Type</th>

            <th>Expected Set Value</th>


          </tr>

        </thead>

        <tbody class="parameter_table">

        </tbody>

      </table>

      </div>

   </div>

 </div>


查看完整回答
反對 回復 2022-09-29
  • 1 回答
  • 0 關注
  • 84 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號