如何使这个 jquery 函数更简洁?
我的 asp.net 项目中的一个通用 javascript 文件中有此代码。
每当我将鼠标悬停在受此函数影响的按钮之一上时,jQuery-Lint 就会返回“您多次使用同一个选择器”。
//turns all the buttons into jqueryUI buttons
//#mainBody is on the master page, #childBody is on the modal page.
$("#mainBody button, #mainBody input:submit, #mainBody input:button, #childBody button, #childBody input:submit, #childBody input:button").livequery(function () {
$(this).button().each(function (index) {
$(this).ajaxStart(function () {
$.data(this, "old_button_val", $(this).val());
$.data(this, "old_button_disabled", $(this).button("option", "disabled"));
$(this).button("option", "disabled", true).val("Wait...");
}).ajaxStop(function () {
$(this).val($.data(this, "old_button_val")).button("option", "disabled", $.data(this, "old_button_disabled"));
}).ajaxError(function () {
$(this).val($.data(this, "old_button_val")).button("option", "disabled", $.data(this, "old_button_disabled"));
});
});
});
有人提出了类似的问题这里。
I have this code in a common javascript file in my asp.net project.
jQuery-Lint returns "You've used the same selector more than once" whenever I mouse over one of the buttons that was affected by this function.
//turns all the buttons into jqueryUI buttons
//#mainBody is on the master page, #childBody is on the modal page.
$("#mainBody button, #mainBody input:submit, #mainBody input:button, #childBody button, #childBody input:submit, #childBody input:button").livequery(function () {
$(this).button().each(function (index) {
$(this).ajaxStart(function () {
$.data(this, "old_button_val", $(this).val());
$.data(this, "old_button_disabled", $(this).button("option", "disabled"));
$(this).button("option", "disabled", true).val("Wait...");
}).ajaxStop(function () {
$(this).val($.data(this, "old_button_val")).button("option", "disabled", $.data(this, "old_button_disabled"));
}).ajaxError(function () {
$(this).val($.data(this, "old_button_val")).button("option", "disabled", $.data(this, "old_button_disabled"));
});
});
});
A similar question was asked here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免责声明:未经测试,因此不保证有效。
Disclaimer: Not tested, therefore not guaranteed to work.