jquery中对动态生成的标签响应click事件(一)

时间:2024-07-16 22:06:50

参考自:http://my.oschina.net/lishixi/blog/31612

<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../themes/icon.css"/>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<script>
jQuery(document).ready(function($) { $('#clickme').bind('click', function() { var html = "<div class='clickyou'>Another target</div>";
$('.clickyou').live('click', function() {
alert("Successful click.");
}); $("#divContent").html(html); $('#experimentDialog').dialog('open');
}); $(function() {
$("#experimentDialog").dialog( {
bgiframe : true,
autoOpen : false,
height : 400,
width : 600,
modal : true,
draggable : true
});
}); }); </script>
</head>
<body>
<a id="clickme" class="easyui-linkbutton">click me</a>
  <div id="experimentDialog" title="系统实验列表" closed="true">
<div id="divContent"></div>
</div>
</body>
</html>