下面的代码工作正常。但是,如果我将 newPara() 中的 html 字符串更改为<textarea></textarea><button id="someId">Save</button>
或<textarea></textarea><input type="button" value="Save"/>
它不起作用。这有什么问题?
我需要该 id 属性来删除新附加的 html。
有什么建议么!
谢谢!
<html>
<head>
<style>
p { background:yellow; font-weight:bold; cursor:pointer; padding:5px; }
p.over { background: #ccc; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div id="aDiv">
<p>Click me!</p>
</div>
<span></span>
<script>
$("body").delegate("p", "click", newPara);
$("body").undelegate("button", "click", newPara).find("#adiv").html("<p>Click me!</p>");
function newPara() {
var html = "<textarea></textarea><button>Save</button>";
$(this).after(html);
}
</script>
</body>
</html>