js给div动态添加控件,然后给这个控件动态添加事件
2024-08-26 14:22:38
<%@ 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>
最新文章
- Delphi 关键字详解[整理于 ";橙子"; 的帖子]
- gulp任务
- Python-操作Memcache、Redis、RabbitMQ、
- 九幽2015年Q3 WP市场份额细分报告
- stretchableImageWithLeftCapWidth 的使用方法
- JQuery 表格 隔行换色 和鼠标滑过的样式
- iOS xcuserdata
- [TypeScript] Installing TypeScript and Running the TypeScript Compiler (tsc)
- 分享整理的sql脚本
- 安装mysql时提示The host &#39;xxx&#39; could not be looked up with resolveip的解决办法
- Swift - AppDelegate.swift类中默认方法的介绍
- html中滚动栏的样式
- 微信应用号开发知识贮备之Webpack实战
- Bootstrap中关闭第二个模态框时出现的问题和解决办法
- Python3入门基础--str常用方法
- Java 中单引号和双引号的区别
- 解决镜像无法删除的问题multiple repositories
- 【K8S学习笔记】Part1:使用端口转发访问集群内的应用
- 解决windows下vim中文乱码
- Suggestion: add &#39;tools:replace=";android:value";&#39; to <;meta-data>; element at AndroidManifest.xml:25:5-27:41 to override.