本文介绍了从外部调用jQuery中定义的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的aspx页面: -
My aspx page:-
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.2.custom.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//lots of other code here....
function showMessage(){
$("#msgDiv").dialog({
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
},
resizable: true,
show: "explode",
position: "center",
closeOnEscape: true,
draggable: false
});
}
});
</script>
从上面的页面触发的另一个aspx弹出页面
Another aspx pop up page which is triggered from the above page
<script type="text/javascript">
window.opener.document.getElementById("msgDiv").innerHTML = <%=MessageToShow%>; //works very well for me.
window.opener.document.showMessage(); // I am unable to access it like this?
window.close();
</script>
基本上我想打电话给 showMessage()
从弹出窗口。我还有其他逻辑可以在两个页面中执行。
Basically I want to call showMessage()
from the pop up window. I also have other logics to perform in both pages.
推荐答案
据我所知,你想做什么,可以'完成。那么,我们究竟能做些什么呢?
As far as I know, what you want to do, can't be done. So, what exactly can we do?
我认为最简单的想法就是将 showMessage
移到 ready
函数,只需从内部调用它。
I think the simpliest think would be to move showMessage
outside of the ready
function, and just call it from within.
现在,如果它必须在该函数中定义,请make它是一个命名函数:
Now, if it really must be defined within that function, make it a named function:
function calledonready()
{
/// stuff
function showMessage(){
/// stuff
}
}
$(document).ready(calledonready);
window.opener.document.calledonready.showMessage();
这篇关于从外部调用jQuery中定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!