zoukankan      html  css  js  c++  java
  • 一个非常隐蔽的错误

    <form id="Form1" method="post" runat="server">
        
    <FONT face="宋体">
            
    <asp:button id="submit" runat="server" />
            
    <asp:dropdownlist id="ddl" runat="server" autopostback="true">
                
    <asp:ListItem>aaa</asp:ListItem>
                
    <asp:ListItem>bbb</asp:ListItem>
                
    <asp:ListItem>ccc</asp:ListItem>
            
    </asp:DropDownList>
        
    </FONT>
    </form>

    当选择DropDownList中的一项时,在PostBack的过程中会发生javascript错误,它会指出“Microsoft JScript 运行时错误: 对象不支持此

    属性或方法”。
    为什么呢?因为在PostBack后,ASP.NET会生成一个dopostback的javascript方法:

    function __doPostBack(eventTarget, eventArgument) { 
    var theform = document.Form1; 
    theform.__EVENTTARGET.value 
    = eventTarget; 
    theform.__EVENTARGUMENT.value 
    = eventArgument; 
    theform.submit(); 

    而当我们使用submit的id在form中提交的时候,它会以为theform.submit是指你所定义的id为submit的控件,而不是一个方法,所以就会出

    现上述错误了。
    看来在定义一些控件的ID的时候还是要尽量避免一些涉及到javascript方法的一些名称。

  • 相关阅读:
    堆和栈的区别
    九度OJ 1108 堆栈的使用
    九度OJ 1201 二叉排序树
    jQuery笔记——基础知识
    JavaScript笔记——事件
    一些知识
    JavaScript笔记——BOM的操作和浏览器的检测
    JavaScript笔记——面向对象与原型
    JavaScript笔记——基础知识(二)
    JavaScript笔记——正则表达式
  • 原文地址:https://www.cnblogs.com/xiaodi/p/145578.html
Copyright © 2011-2022 走看看