我需要访问$(document).ready()
范围内外的元素。
假定以下代码:
var text__holder = $('#text__holder');
$(function() {
text__holder.text('Inside DOM ready');
/*
SOME MORE ACTION WITH ELEMENT
*/
});
var writeSomeTxt = function() {
text__holder.text('Outside DOM ready');
};
writeSomeTxt();
在这种情况下不能访问该函数内的元素。 JS也在外部.js
文件中,该文件包含在页面的<head>
部分,我不能在其他地方替换它。
我目前的“解决方法”因为这是:
var text__holder = $('#text__holder');
$(function() {
text__holder.text('Inside DOM ready');
/*
SOME MORE ACTION WITH ELEMENT
*/
});
var writeSomeTxt = function() {
$(function() {
text__holder.text('Outside DOM ready');
});
};
writeSomeTxt();
确定。你的问题是什么? – David
如果你把这个代码放在'