Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript:Return false不起作用:即使在我按下cancel之后,代码也会被执行_Javascript_Asp.net_Return - Fatal编程技术网

Javascript:Return false不起作用:即使在我按下cancel之后,代码也会被执行

Javascript:Return false不起作用:即使在我按下cancel之后,代码也会被执行,javascript,asp.net,return,Javascript,Asp.net,Return,Javascript:Return false不起作用,即使在我按下cancel之后,代码也会被执行 我试图用一个按钮执行两个javascripts。当第二个脚本执行时,即使单击“取消”,代码也会执行。下面是代码。谁能帮帮我吗 <script type="text/javascript" language="javascript"> var TargetBaseControl = null; window.onload = function () { try {

Javascript:Return false不起作用,即使在我按下cancel之后,代码也会被执行

我试图用一个按钮执行两个javascripts。当第二个脚本执行时,即使单击“取消”,代码也会执行。下面是代码。谁能帮帮我吗

<script type="text/javascript" language="javascript">
  var TargetBaseControl = null;
  window.onload = function () {
    try {
      //get target base control.
      TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
    } catch (err) {
      TargetBaseControl = null;
    }
  }

  function TestCheckBox() {
    if (TargetBaseControl == null) return false;
    //get target child control.
    var TargetChildControl = "chkSelect";
    //get all the control of the type INPUT in the base control.
    var Inputs = TargetBaseControl.getElementsByTagName("input");
    for (var n = 0; n < Inputs.length; ++n)
    if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 && Inputs[n].checked) return true;
    alert('Please select at least one Request to Close!');
    return false;
  }

  function UpdateConfirmation() {
    if (confirm("Are you sure, you want to close selected request ?") == true) return true;
    else return false;
  }
</script>




<asp:Button ID="btnUpdate" runat="server" 
        OnClick="btnUpdate_Click" Text="Close Request" 
         OnClientClick="var b = TestCheckBox(); if (b) UpdateConfirmation(); return b"/>

var TargetBaseControl=null;
window.onload=函数(){
试一试{
//获得目标基地控制权。
TargetBaseControl=document.getElementById(“”);
}捕捉(错误){
TargetBaseControl=null;
}
}
函数TestCheckBox(){
if(TargetBaseControl==null)返回false;
//获取目标子控件。
var TargetChildControl=“chkSelect”;
//获取基本控件中输入的类型的所有控件。
var Inputs=TargetBaseControl.getElementsByTagName(“输入”);
对于(变量n=0;n=0&&Inputs[n].checked)返回true;
警报('请至少选择一个要关闭的请求!');
返回false;
}
函数UpdateConfirmation(){
如果(确认(“您确定要关闭所选请求吗?”)==true)返回true;
否则返回false;
}

您应该使用两个
asp:Button
(一个按钮不可见)。例如-

//some code
//
function UpdateConfirmation() {
    if (confirm("Are you sure, you want to close selected request ?") == true) 
    document.getElementById('<%= this.btn.ClientID %>').click();//fire hidden button
    else return false;
  }
</script>


<asp:Button ID="btnUpdate" runat="server" Text="Close Request" 
   OnClientClick="var b = TestCheckBox(); if (b) UpdateConfirmation(); return b" 
   UseSubmitBehavior="false"/>
<asp:Button ID="btn" runat="server" Text="Button" 
    OnClick="btnUpdate_Click" CssClass="VisibleFalse" TabIndex="-1" />
//一些代码
//
函数UpdateConfirmation(){
if(确认(“您确定要关闭所选请求吗?”)==true)
document.getElementById(“”)。单击();//激发隐藏按钮
否则返回false;
}

btn
是隐藏按钮,
btnUpdate
是主按钮。
不要忘记将
usemmitbehavior
设置为
false

编辑:使用
document.getElementById(“”)。单击()而不是
document.getElementById(ClientdPrefix+“btn”)。单击()



单击按钮只需一个javascript代码。

您应该使用两个
asp:button
(一个按钮不可见)。例如-

//some code
//
function UpdateConfirmation() {
    if (confirm("Are you sure, you want to close selected request ?") == true) 
    document.getElementById('<%= this.btn.ClientID %>').click();//fire hidden button
    else return false;
  }
</script>


<asp:Button ID="btnUpdate" runat="server" Text="Close Request" 
   OnClientClick="var b = TestCheckBox(); if (b) UpdateConfirmation(); return b" 
   UseSubmitBehavior="false"/>
<asp:Button ID="btn" runat="server" Text="Button" 
    OnClick="btnUpdate_Click" CssClass="VisibleFalse" TabIndex="-1" />
//一些代码
//
函数UpdateConfirmation(){
if(确认(“您确定要关闭所选请求吗?”)==true)
document.getElementById(“”)。单击();//激发隐藏按钮
否则返回false;
}

btn
是隐藏按钮,
btnUpdate
是主按钮。
不要忘记将
usemmitbehavior
设置为
false

编辑:使用
document.getElementById(“”)。单击()而不是
document.getElementById(ClientdPrefix+“btn”)。单击()



这只是一个javascript代码,可以触发一个按钮点击。

您应该在调用函数时添加return

<asp:Button ID="btnUpdate" runat="server" 
        OnClick="btnUpdate_Click" Text="Close Request" 
         OnClientClick="if(TestCheckBox()) return UpdateConfirmation();"/>

调用函数时应添加return

<asp:Button ID="btnUpdate" runat="server" 
        OnClick="btnUpdate_Click" Text="Close Request" 
         OnClientClick="if(TestCheckBox()) return UpdateConfirmation();"/>


感谢Shafeeq和所有其他人

工作代码

<script type="text/javascript" language="javascript">

             var TargetBaseControl = null;

             window.onload = function () {
                 try {
                     //get target base control.
                     TargetBaseControl =
       document.getElementById('<%= this.GridView1.ClientID %>');
                 }
                 catch (err) {
                     TargetBaseControl = null;
                 }
             }

             function TestCheckBox() 
             {
                 if (TargetBaseControl == null) return false;

                 //get target child control.
                 var TargetChildControl = "chkSelect";

                 //get all the control of the type INPUT in the base control.
                 var Inputs = TargetBaseControl.getElementsByTagName("input");

                 for (var n = 0; n < Inputs.length; ++n)
                     if (Inputs[n].type == 'checkbox' &&
        Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 &&
        Inputs[n].checked)
                         return true;

                 alert('Please select at least one Request to Close!');
                 return false;
             }


          function UpdateConfirmation() {
              if (confirm("Are you sure, you want to close selected request ?") == true)


                     return true;

                 else return false;

             }

var TargetBaseControl=null;
window.onload=函数(){
试一试{
//获得目标基地控制权。
目标基地控制=
document.getElementById(“”);
}
捕捉(错误){
TargetBaseControl=null;
}
}
函数TestCheckBox()
{
if(TargetBaseControl==null)返回false;
//获取目标子控件。
var TargetChildControl=“chkSelect”;
//获取基本控件中输入的类型的所有控件。
var Inputs=TargetBaseControl.getElementsByTagName(“输入”);
对于(变量n=0;n=0&&
输入[n]。已选中)
返回true;
警报('请至少选择一个要关闭的请求!');
返回false;
}
函数UpdateConfirmation(){
if(确认(“您确定要关闭所选请求吗?”)==true)
返回true;
否则返回false;
}



感谢Shafeeq和所有其他人

工作代码

<script type="text/javascript" language="javascript">

             var TargetBaseControl = null;

             window.onload = function () {
                 try {
                     //get target base control.
                     TargetBaseControl =
       document.getElementById('<%= this.GridView1.ClientID %>');
                 }
                 catch (err) {
                     TargetBaseControl = null;
                 }
             }

             function TestCheckBox() 
             {
                 if (TargetBaseControl == null) return false;

                 //get target child control.
                 var TargetChildControl = "chkSelect";

                 //get all the control of the type INPUT in the base control.
                 var Inputs = TargetBaseControl.getElementsByTagName("input");

                 for (var n = 0; n < Inputs.length; ++n)
                     if (Inputs[n].type == 'checkbox' &&
        Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 &&
        Inputs[n].checked)
                         return true;

                 alert('Please select at least one Request to Close!');
                 return false;
             }


          function UpdateConfirmation() {
              if (confirm("Are you sure, you want to close selected request ?") == true)


                     return true;

                 else return false;

             }

var TargetBaseControl=null;
window.onload=函数(){
试一试{
//获得目标基地控制权。
目标基地控制=
document.getElementById(“”);
}
捕捉(错误){
TargetBaseControl=null;
}
}
函数TestCheckBox()
{
if(TargetBaseControl==null)返回false;
//获取目标子控件。
var TargetChildControl=“chkSelect”;
//获取基本控件中输入的类型的所有控件。
var Inputs=TargetBaseControl.getElementsByTagName(“输入”);
对于(变量n=0;n=0&&
输入[n]。已选中)
返回true;
警报('请至少选择一个要关闭的请求!');
返回false;
}
函数UpdateConfirmation(){
if(确认(“您确定要关闭所选请求吗?”)==true)
返回true;
否则返回false;
}



您从事件处理程序返回
b
,而不是
UpdateConfirmation
的返回值@Aditya我在您询问的答案中添加了一些解释。您从事件处理程序返回
b
,而不是
UpdateConfirmation