Javascript 如何调用初始化函数
调用初始化函数时遇到问题。该功能是否有一定的范围?我只能在主函数中调用它吗?我可以在外部JavaScript文件中调用它吗Javascript 如何调用初始化函数,javascript,jquery,Javascript,Jquery,调用初始化函数时遇到问题。该功能是否有一定的范围?我只能在主函数中调用它吗?我可以在外部JavaScript文件中调用它吗 $main(function(){ org.mathdox.formulaeditor.FormulaEditor = $extend(Object, { textarea : null, canvas : null, presentation : null, cursor : null, i
$main(function(){
org.mathdox.formulaeditor.FormulaEditor = $extend(Object, {
textarea : null,
canvas : null,
presentation : null,
cursor : null,
initialize : function(textarea, canvas) {...},
other functions...
}
你是如何调用它的,从哪里调用的?假设你的意思是
$.extend
,你不能直接调用org.mathdox.formulaeditor.formulaeditor.initialize()
你能把代码放在你试图调用它的地方,以及你创建formulaeditor实例的地方吗?我想我必须解释一下文件结构。我的主HTML引用了两个JavaScript文件(head标记中的main.js和formula_editor.js)另一个JS文件名为FEconcatenation.JS。上面的代码在FEconcatenation.JS中。我调用它的地方是在formula_editor.JS中。我创建了一个新的textarea,并试图通过使用initialize(newTextArea)
来初始化它。我是否必须在formula_editor.JS文件中创建FormulaEditor的实例?
$('#fe_reset').click(function () {
$('#divTextArea').remove();
var textareadiv = document.createElement('div');
textareadiv.className = 'formula_editor_textarea';
textareadiv.id = 'divTextArea';
var thetextarea = document.createElement('textarea');
thetextarea.className = 'mathdoxformula';
thetextarea.id = 'formula1';
thetextarea.style.rows = '10';
thetextarea.style.cols = '80';
textareadiv.appendChild(thetextarea);
document.getElementById('formula_editor_container').insertBefore(textareadiv, document.getElementById('fe_cancel'));
initialize(thetextarea); // CAN I NOT CALL IT LIKE THIS?
$('#fe_save').css({'cursor': 'default', 'opacity': '0.55'}).attr('disabled','disabled');
});