【发布时间】:2011-03-10 16:25:32
【问题描述】:
我有一些代码可以从另一个文件加载一些 html,它可以正常工作。但我正在努力从这个新加载的数据中访问元素。
我有这个代码:
var widgetSettings = $("<div>").addClass("widgetsettings").load('dashboard/chart-settings-form.php #editChartForm');
widgetSettings.appendTo(widget.element);
//so far so good...
widget.element.find('.date').each(function(i){
$(this).datetimepicker(); //this doesn't work
console.log('testing... '+$(this).attr('id')); //this doesn't even work...
});
我希望它能在从上述 url 加载的“#editChartForm”表单中找到这些文本框(它们在一个表格中):
<input type="text" name="datefrom" id="datefrom" class="date" /> To: <input type="text" name="dateto" id="dateto" class="date" />
肯定正在加载 html。只是真的很困惑为什么我不能从 load() 事件中访问任何元素。
我还想对同一个表单上的取消按钮应用点击功能,我发现使其工作的唯一方法是在加载之前将其置于“实时”功能中:
$('.cancel').live('click', function() {
//actions here...
});
有什么想法吗?
【问题讨论】:
-
哦,别担心。它只是父 div 元素/对象 :)
标签: javascript jquery function append load