English 中文(简体)
无法成功调用 JJS 文件 2 中定义的函数 从 JJS 文件 1 中的函数调用 。 该页面已装入/ 点击事件
原标题:Unsuccessfully calling a function defined in JS file 2 from a function in JS file 1 AFTER the page has loaded/on-click event

我有两个Javascript文件,我将大大精简,简化手头的问题。

form.js

function open_action_dialog(){
   // code to open the dialog..

   // If [Return] is pressed when focus is on the #action field, call the action confirmation function defined in the second javascript file.
   $( #action ).keypress(function(e){
      var fn_name = "action_confirm";
      if(e.which == 13)
         window[fn_name]();
   });
}

blog.form.js

$(function (){
   $("#dialog_action_open").click(function() { 
       open_action_dialog(); 
   });

   function action_confirm(){
     alert( action confirmed );
     return;
   }
});

所以在我的页面上,当单击打开动作对话框时,我有一个 id dialog_action_open 的按钮。 这是第二个文件的一个函数, 从第一个文件成功调用函数 。

在对话框中,有一个输入文本字段,有 id action 的输入文本字段,在那里我设置了它,这样,如果用户在光标聚焦于字段时按下 [return] ,它应该调用第二个文件中定义的 action_confirm () 函数。它确实会调用按键事件,但不会从第二个文件中调用该函数;在 Google 代码检查员内部,错误是 :

未标记的 TypeError: 对象 [目标窗口] 的属性动作_ conference

因此,我的问题是,我需要做些什么才能从第一个文件中的函数内部成功调用第二个文件的函数? 记住, 我意识到您不能立即调用稍后定义的函数。 但是, 尽管我的动作_ confirmed () 函数在调用第一个文件的函数后被定义了, 但考虑到调用发生在页面已加载的事后, 更具体地说, 在页面上有一个点击事件之后, 这个技术性模拟是否已经存在?

如果能开明点,我将不胜感激。

非常感谢。

最佳回答

因为您试图调用的函数被包裹在另一个函数中, 它在您另一个 JS 的函数中是看不见的 。

您可以删除 $( 函数 () /code > (和关闭 < code > ); )

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签