本文介绍了如何$由JavaScript p $ pvent回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实这code是firfox mozila运作良好,但它不是在IE8工作

<asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="btnPrimary" OnClientClick="return doSubmit('this');"
        OnClick="btnSubmit_Click" />
      <script type="text/javascript">
           function doSubmit()
           {
            var ansLength = oDOM.body.innerText.trim().length;
            if (ansLength == 0 && smielyPresent == -1)
              {
              alert("you cannot submit blank answer");
              return false;
              }
           }
    </script>

     protected void btnSubmit_Click(object sender, EventArgs e)
    {
      // i am doing some stuff
    }

在这里,我想prevent回发时 answerlength == 0;
但是当答案长度== 0 则警告警报(你无法提交空白答案)消息,回发到服务器的IO要prevent它,我该怎么办?

here i want to prevent postback when answerlength == 0 ;but when answer length ==0 then it alert alert("u can't submit blank answer") message and postback to server io want to prevent it how i do ?

推荐答案

它不工作,因为你在你的JavaScript有一个脚本错误。

It's not working since you have a script error in your javascript.

<script type="text/javascript">
    function doSubmit()
    {
        //I've removed the first equal sign
        var ansLength = oDOM.body.innerText.trim().length;
        if (ansLength == 0 && smielyPresent == -1) //typo on smielyPresent ?
        {
            alert("u can't submit blank answer")
            return false;
        }
    }
</script>

这篇关于如何$由JavaScript p $ pvent回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:23