有一个带有占位符的网页(一个普通的 div)。通过 ajax 调用,我将 a<form>
和 a加载<script>
到占位符中。该脚本包含初始化表单所需的javascript(例如,禁用控件以使表单成为只读等)。这是我的一段代码;它有效,但注释部分不起作用。因为脚本引擎找不到对象 tristate_DisableControl,它是我通过 ajax 调用的脚本之一中的一个函数。
$(document).ready(function() {
// $('#site_preferences_content div').each(function() {
// if (typeof (window.tristate_DisableControl) == 'undefined') {
// if (typeof (window.console) != 'undefnied')
// console.log((new Date()).toTimeString() + ' not logable');
// pausecomp(1000);
// }
// else
// tristate_DisableControl(this);
// }); //end $('#site_prefrences_content div').each()
setTimeout(function() {
$('#site_preferences_content div').each(function() { tristate_DisableControl(this); })
}, 1000);
});
我认为在 $(document).ready() 执行时 DOM 将被正确加载......