$( document ).ready(function() {
console.log( "ready!" );
var counter = 0;
$("button").click(function() {
e="<p class='test' _=\"on click append 'click me' to value of the #search\">click me</p>"
$("h2").append(e)
});
// With on():
$("h2").on("click", "p.test", function(){
alert($(this).text());
});
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/hyperscript.org@0.8.1"></script>
<input id="search" />
<button>generate new element</button>
<h2></h2>
jquery可以工作,但是超文本不会将文本附加到输入框中。
发布于 2022-04-22 13:05:21
好吧,你的超文本代码看起来像你想的那样工作。jQuery似乎是坏的。如果您打算附加到用户正在键入的值中。放弃附加的jQuery,只需使用_hyperscript。
<script src="https://unpkg.com/hyperscript.org@0.8.1"></script>
<input id="search" />
<button _="on click append 'click me' to value of the #search">generate new element</button>
<h2></h2>https://stackoverflow.com/questions/71904743
复制相似问题