如何从 JQuery 块外部调用 JQuery
好吧,问题确实没有意义。情况是这样的。我有使用“Anthem”ajax 的遗留代码,Anthem 允许挂钩到回调前和回调后步骤。因此,如果我有这样的代码,如何在 cmdSave_PostCallBack 中的 .each 块下执行代码。我知道我不能按原样调用它,但是有什么方法可以允许在加载 doc 时以及在 postcallback 函数中执行此块?
jQuery(document).ready(function() {
//select all anchors in divMain element and attach click handler
$("#<%=divSelectorLinks.ClientID %> a").click(function(e) {
e.preventDefault();
var content = $(this.getAttribute("rel"));
//attach nyromodal
$.nyroModalManual({
bgColor: '#efefef',
width: 200,
content: content
})
})
//display currently selected value
.each(function(i) {
var selectionText = $(this.getAttribute("rel")).find(':selected')[0].innerHTML;
if (selectionText.substr(0, 4) == "All ") {
this.innerHTML += ": All";
}
else {
this.innerHTML = this.innerHTML + ": " + selectionText;
}
});
return false;
});
function cmdSave_PostCallBack() {
}
Ok, question does not really make sense. Here is the situation. I have legacy code using "Anthem" ajax, and Anthem allows to hook into pre and post callback steps. So if I have code like this, how do I execute code under .each block in cmdSave_PostCallBack. I know I cannot call it the way it is, but what would be a way that would allow this block to be executed when doc is loaded and also in the postcallback function?
jQuery(document).ready(function() {
//select all anchors in divMain element and attach click handler
$("#<%=divSelectorLinks.ClientID %> a").click(function(e) {
e.preventDefault();
var content = $(this.getAttribute("rel"));
//attach nyromodal
$.nyroModalManual({
bgColor: '#efefef',
width: 200,
content: content
})
})
//display currently selected value
.each(function(i) {
var selectionText = $(this.getAttribute("rel")).find(':selected')[0].innerHTML;
if (selectionText.substr(0, 4) == "All ") {
this.innerHTML += ": All";
}
else {
this.innerHTML = this.innerHTML + ": " + selectionText;
}
});
return false;
});
function cmdSave_PostCallBack() {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建另一个函数(我们将其称为驴),并在每个中使用它:(
抱歉,格式有点混乱)
Create another function (we shall call it donkey), and use that in the each:
(sorry, the formatting is a little messed up)
是不是就像将
.each
剥离到自己的函数中并从 Ready 和cmdSave_PostCallBack
中调用它一样简单?像这样的东西:
Would it be as simple as ripping the
.each
out into its own function and calling it both from the ready and thecmdSave_PostCallBack
?Something like: