我的代码和我的问题是:
<script type="text/javascript">
$(document).ready(function() {
// this variable is used to set the dynamic elements
tagFlag = '';
$("#a1").click(function(event) {
event.preventDefault();
tagFlag = 'me'; // setting the element which I want to trigger later
});
$('#'+tagFlag).click(function(e) {
// do sthing here
});
});
</script>
</head>
<body>
<a href="">make the element</a>
<p id="me">some words here</p>
</body>
</html>
但是。当我设置 tagFlag 并单击“p”时,什么也没有发生。顺便说一句。当 tagFlag 没有设置时出现错误。那么。我怎样才能得到我想要的东西?
非常感谢!!
最佳答案
也许您应该看看 jQuery live()
方法,它将事件分配给所有现有和 future 的元素。
关于javascript - jquery.Event 动态元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3695329/