<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="JsExerciseTow.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        window.onload = function () {
            var divAppend = document.getElementById("appendBtn");
            var obj = document.createElement("Input");
            divAppend.appendChild(obj);
            obj.type = "button";
            obj.value = "我是进加上的Input";
           
            if (window.addEventListener) {
                //其它浏览器的事件代码: Mozilla, Netscape, Firefox
                //添加的事件的顺序即执行顺序 //注意用 addEventListener 添加带on的事件,不用加on 
                obj.addEventListener('focus', add, false);
            }
            else {
                //IE 的事件代码 在原先事件上添加 add 方法
                obj.attachEvent('onfocus', add);
            }
          
        }
        function add() {
            alert("我是追加按钮的事件");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="appendBtn">
    
    </div>
    </form>
</body>
</html>

 

posted on 2015-04-20 16:07  王洪洪  阅读(1188)  评论(0编辑  收藏  举报