html 当一个按钮触发另一个按钮时,Jquery input .瓦尔()返回undefined

ibrsph3r  于 2022-12-16  发布在  jQuery
关注(0)|答案(1)|浏览(135)

我有多个按钮,需要同时激活。当每个按钮被点击从输入它返回什么是类型。问题是,我需要所有的按钮被同时发射关闭。当我有一个单独的按钮发射关闭这些按钮,虽然我得到未定义的,而不是输入。

$(document).on("click", "#devSaveBtn", function () {
  if (
    $("#primaryBtn").trigger("click") &&
    $("#secondaryBtn").trigger("click") &&
    $("#thirdBtn").trigger("click")
  ) {
    var getInput = $(this)
      .closest("td")
      .find("input[name='Object Name']")
      .val();
    console.log("Input = " + getInput);

    var getInput2 = $(this)
      .closest("td")
      .find("input[name='Project Name']")
      .val();
    console.log("Input2 = " + getInput2);

    var getInput3 = $(this)
      .closest("td")
      .find("input[name='Description']")
      .val();
    console.log("Input3 = " + getInput3);
  } else {
    console.log("This is not working");
  }
});
<button type="button" input type="submit" id="devSaveBtn" class="devbutton devinithidden readonlyhidden" title="Reset Changes" style="visibility: visible; background-color: #f4d8b4;"><i class="fa fa-save"></i>
  Save</button>
<td class="noncomponentswidth" id="recordObjName">
  <p>
    <input type="text" id="OBJ_NAME" name="Object Name" placeholder="" required minlength="8">
    <button id="primaryBtn">Primary</button>
  </p>
  <button style="display: none;">Submit</button>
</td>
<td class="noncomponentswidth" id="recordProjectName">
  <input type="text" id="DEPLOYER_PROJECT" name="Project Name" placeholder="">
  <button id="secondaryBtn">Secondary</button>
</td>

<td class="noncomponentswidth" id="recordDeployerCandidate" placeholder="">
  <input type="text" id="DESCRIPTION" name="Description" placeholder="" style="resize: vertical; width: 40em; height: 85px;">
  <button id="thirdBtn">Third</button>
</td>
b4wnujal

b4wnujal1#

$(document).on("click", "#devSaveBtn", function () {
  var getInput = $("input");
  for (var i = 0; i < getInput.length; i++)
    console.log(getInput[i].id, " => Input", i, " = ", getInput[i].value);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.js" integrity="sha512-CX7sDOp7UTAq+i1FYIlf9Uo27x4os+kGeoT7rgwvY+4dmjqV0IuE/Bl5hVsjnQPQiTOhAX1O2r2j5bjsFBvv/A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<button type="button" input type="submit" id="devSaveBtn" class="devbutton devinithidden readonlyhidden" title="Reset Changes" style="visibility: visible; background-color: #f4d8b4;"><i class="fa fa-save"></i>
  Save</button>
<td class="noncomponentswidth" id="recordObjName">
  <p>
    <input type="text" id="OBJ_NAME" name="Object Name" placeholder="" required minlength="8">
  </p>
</td>
<td class="noncomponentswidth" id="recordProjectName">
  <input type="text" id="DEPLOYER_PROJECT" name="Project Name" placeholder="">
</td>
<td class="noncomponentswidth" id="recordDeployerCandidate" placeholder="">
  <input type="text" id="DESCRIPTION" name="Description" placeholder="" style="resize: vertical; width: 40em; height: 85px;">
</td>

相关问题