在html中關於若是function的函數名和input的name同樣會發生怎樣的現象

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="2_PageMethods.aspx.cs" Inherits="MsdnWebCast_WebSerivce1._2_PageMethods" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
    </div>
        <script type="text/javascript">
            function getCurrentTime() {
                PageMethods.GetCurrentDatetime(onsuccessed);
            }
            function onsuccessed(result) {
                alert(result);
            }
        </script>
        <input type="button" name="getCurrentTime" value="get Current Time " onclick="getCurrentTime()" />
    </form>
</body>
</html>

能夠看到上面的代碼中有一個js的function名字叫getCurrentTime,另外咱們還有一個input的那麼也叫getCurrentTime,那麼運行期會發生什麼現象呢javascript

看看IE中的效果html

image

看看chrome中的效果java

 

image

 

緣由:系js中一切皆對象,無論什麼類型均不能重名,重名的話,即會致使後一個對系那個覆蓋前一個對象。chrome

 

若是把input的name改爲其餘名字,好比getCurrentTime1,就能夠了。ui

相關文章
相關標籤/搜索