对于任何类型的 Web 开发,我都不是很有经验,更不用说 jquery 和 ajax,我需要使用它们,所以我遇到了困难。
我正在开发一个项目,该项目要求我在单击名为“重新打开”的单独按钮时将两个复选框重新绘制为“未选中”。现在我正在使用的代码是:
$('.reopenBtn').click(function() {
var confirm_reopen = confirm("Are you sure you want to open this opportunity back up?");
if (confirm_reopen) {
var href = 'cfcs/opportunity.cfc';
var method = 'ReopenOp';
var opsid = $(this).parent().parent().attr('id');
$('#' + opsid).ajaxSuccess(function() {});
$.post(href, {
method: method,
opsid: opsid
});
$('.lost').removeAttr('checked');
$('.won').removeAttr('checked');
}
});
此代码的问题在于,它重新绘制了页面上复选框的所有实例,而不仅仅是赢得和失去的复选框的特定实例。我正在寻找的是这样的:
$(this).('.lost').removeAttr('checked');
$(this).('.won').removeAttr('checcked');
就像我说的,我对大多数 Web 开发语言都不是很有经验,所以我真的不知道能够做到这一点的语法。我的限制只是能够阅读和理解代码足以调整和更改它,而不是从头开始任何新的东西。
任何帮助将不胜感激!
最佳答案
您可以将其作为选择器中的上下文传递 http://api.jquery.com/jQuery/#selector-context
$('.lost,.won',this).removeAttr('checked');
仅供引用,.prop()从 jQuery 1.6+ 开始,这是在属性中设置禁用的正确方法
关于jquery - 在 JQuery 中引用类的当前对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13461908/