[英]Switch statement passing in id of button not functioning properly
I am trying to use a switch statement switch (buttionId)
, passing in the id of the button that I am selecting, however, the function is not firing properly. 我正在尝试使用switch语句
switch (buttionId)
,传入我选择的按钮的ID,但是该功能无法正常触发。 Here is my function: 这是我的功能:
function PickDiagCode(btnNum, button) {
var txtID;
var strId;
//var buttonId = $("input[id*=btnHeaderDiagPick]").attr("id");
switch (button.value) {
case "Clear":
switch (button.id) {
case "btnHeaderDiagPick1":
//Do Work
case "btnHeaderDiagPick2":
//Do Work
Here are the buttons: 以下是按钮:
<input class="Button-Search" id="btnHeaderDiagPick1" onclick="document.frmCrgEntry.hdnPickClrDiagCode.value='1';PickDiagCode('1',btnHeaderDiagPick1);"
type="button" name="btnHeaderDiagPick1" runat="server" />
<input class="Button-Search" id="btnHeaderDiagPick2" onclick="document.frmCrgEntry.hdnPickClrDiagCode.value='2';PickDiagCode(2,btnHeaderDiagPick2);"
type="button" name="btnHeaderDiagPick2" runat="server" />
You are missing the document.getElementById()
您缺少
document.getElementById()
switch (btnID.value) {
change to 改成
switch (document.getElementById(btnID).value) {
Your problem appears to be this: 您的问题似乎是这样的:
document.frmCrgEntry.hdnPickClrDiagCode.value='1';
If you remove it everything works just fine. 如果删除它,一切正常。 Here is a fiddle where one button has it, and one doesn't.
这是一个小提琴 ,其中有一个按钮,没有一个按钮。 The button where it is removed, works without issue (for calling the function)
删除该按钮的按钮可以正常工作(用于调用函数)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.