[英]set value for current elements and dynamically added elements in jquery
I have the following code but it doesn't work 我有以下代码,但它不起作用
$("body").delegate("textarea", "ready", function () {
$(this).val("custom value");
});
My intent is set that value for current elements on the dom and future textareas added dynamically to the page, is there a solution? 我的意图是将dom上的当前元素和将来的textareas的值动态添加到页面,有解决方案吗?
.ready
is an event that occurs on the document
, not when other elements are loaded. .ready
是在document
上发生的事件,而不是在加载其他元素时发生的事件。 Unfortunately there is not a graceful solution to this either. 不幸的是,这也没有一个合适的解决方案。 The best suggestion I can make is that after each of your ajax requests complete, to select all
textarea
s and set their values: 我可以提出的最好建议是,在每个ajax请求完成之后,选择所有
textarea
并设置它们的值:
// maybe something similar to this.
$(document).ajaxSuccess(function() {
$('textarea').val('custom value');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.