javascript 按钮未触发JS功能

vaqhlq81  于 2023-01-24  发布在  Java
关注(0)|答案(1)|浏览(145)

我创建了一个按钮,然后这个按钮应该会触发一个JS函数,这个JS函数会调用另一个JS函数。我试着在JS中放入警报函数来测试它是否会触发,但是它没有触发。有人能帮助我吗?
为什么没有引爆?

$(document).ready(function() {
  $("#btnProcess3").attr("disabled", "disabled");
  alert("hi")
  jsProcess(0);

  $("#btnProcess3").click(function() {
    alert("hi")
    $(this).attr("disabled", "disabled");
    jsProcess(1);
  });
});

function jsProcess(action) {
  var page;
  var sDate;
  var sBizDate;
  sDate = $('#txtDate').val();

  if ($('#chkuseBizDate').is(':checked')) {
    sBizDate = $('#txtBizDate').val();
  } else {
    sBizDate = sDate;
  }
  page = "LoadPPSFile_details01.asp?TaskId=<%=sTaskId %>&txtDate=" + (sDate) + "&RunProcess=" + action + "&txtBizDate=" + (sBizDate);
  document.getElementById("IProcess").src = page;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input type="button" name="btnProcess" id="btnProcess3" value="Start - Services" width="250" style="VISIBILITY:show; WIDTH: 150px; HEIGHT: 22px; Background-Color:#1E90FF; Border-Color:white; Color:white; Font-Weight:bold;Font-family:Verdana;Cursor:hand; "
/>
eyh26e7m

eyh26e7m1#

您的代码缺少jsProcess()正在查找的一些代码,但在您删除禁用部分时,按钮按例外情况执行。

$(document).ready(function() {
  // $("#btnProcess3").attr("disabled", "disabled");
  // alert("hi")
  // jsProcess(0);

  $("#btnProcess3").click(function() {
    alert("I'm triggered!")
    $(this).attr("disabled", "disabled");
    // jsProcess(1);
  });
});

function jsProcess(action) {
  var page;
  var sDate;
  var sBizDate;
  sDate = $('#txtDate').val();

  if ($('#chkuseBizDate').is(':checked')) {
    sBizDate = $('#txtBizDate').val();
  } else {
    sBizDate = sDate;
  }
  page = "LoadPPSFile_details01.asp?TaskId=<%=sTaskId %>&txtDate=" + (sDate) + "&RunProcess=" + action + "&txtBizDate=" + (sBizDate);
  document.getElementById("IProcess").src = page;
}
#btnProcess3 {
  VISIBILITY: show;
  WIDTH: 150px;
  HEIGHT: 22px;
  Background-Color: #1E90FF;
  Border-Color: white;
  Color: white;
  Font-Weight: bold;
  Font-family: Verdana;
  Cursor: hand;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input type="button" name="btnProcess" id="btnProcess3" value="Start - Services" width="250">

相关问题