![](/img/trans.png)
[英]How to bind an event handler to an iframe's onload with JQuery?
[英]Jquery: How to dynamically bind a textbox with onload event?
在运行时使用Javascript创建一个textbox
。 当用户单击button
时,它将打开。
<input type="text" id="documentTitle" name="documentTitle" value="<spring:message code="document.Title"/>"
单击时,我要显示突出显示的textbox
文本。
如何使用JQuery触发onload元素?
尝试以下JQuery,但未成功:
$(document).on("load", "#documentTitle" , function() {
myquery.highlightText(this);
});
我不是您真正想要的,但是这里有一些代码可以帮助您?
$(document).ready(function() { alert("on load event fire"); $("button").click(function() { $("textarea").show(); }) });
textarea { display: block; width: 400px; color: black; padding: 10px; text-shadow: 0px 0px 2px rgba(255, 0, 0, 1); height: 120px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea style="display:none">asdasdasd</textarea> <button> show </button>
您没有选择,当任意DOM元素(例如<div>
准备就绪时,不会触发任何事件。
$(document).ready(function(e) { $(document).on("click", "#test", function() { $("#content").append('<input type="text" id="documentTitle" name="documentTitle" value=""/>'); //do your highlight here $("#content #documentTitle").val("test"); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="button" id="test" value="test" /> <div id="content"></div>
如果您确实想要一个事件,则应该创建一个自定义事件
$(document).ready(function(e) {
$(document).on("click", "#test", function() {
$("#content").append('<input type="text" id="documentTitle" name="documentTitle" value=""/>');
$("#content #documentTitle").trigger("myLoadedevent");
});
$(document).on("myLoadedevent", "#documentTitle", function() {
//do your highlight here
alert('event');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.