Javascript 如何向一个onclick函数添加两个响应?html中的onclick是

Javascript 如何向一个onclick函数添加两个响应?html中的onclick是,javascript,jquery,Javascript,Jquery,我正在试图弄清楚,如果使用了其他的点击,如何获得一个点击功能来做一些新的事情。我有三个onclick函数,每个函数在单击时都有单独的反馈语句。它们所附加的divs如下所示: $('#p26_opt1,#p26_opt2,#p26_opt3')。单击(函数(){ //检查是否已选择此div var wasSelected=$(this).data('selected'); document.getElementById(“p26_feedback1”).style.display='block'

我正在试图弄清楚,如果使用了其他的点击,如何获得一个点击功能来做一些新的事情。我有三个
onclick
函数,每个函数在单击时都有单独的反馈语句。它们所附加的
div
s如下所示:

$('#p26_opt1,#p26_opt2,#p26_opt3')。单击(函数(){
//检查是否已选择此div
var wasSelected=$(this).data('selected');
document.getElementById(“p26_feedback1”).style.display='block';
document.getElementById(“p26_feedback2”).style.display='none';
//将其选定状态更改为与以前相反的状态
$(this).data('selected',!wassected);
//跟踪是否使用标志取消选中任何复选框
未选择的变量;
//遍历所有div
$('#p26_opt1,#p26_opt2,#p26_opt3')。每个(函数(){
//如果已经存在未选择的div,或者如果此div
//未选中,设置我们的旗帜
anyUnselected=anyUnselected | |!$(this).data('selected');
});
//如果我们的旗帜显示有人未被发现,请停在这里
如果选择了(anySelected),返回;
//当这三个都检查完后,做你想做的任何事情。
$('#p26_feedback3').show();
});

定期查看存储在设备上的数据,以确定不再需要的内容

删除数据并清空回收站
按照国防部的指导方针清除计算机上的所有数据痕迹
把它放在下周的任务清单上
你还应该做什么?还有更多正确的答案。 不完全是–为什么不现在就做呢?请再试一次。
对要完全处理电子数据,您需要检查和识别旧数据,删除旧数据并清空回收站,并采取进一步措施清除设备上的所有电子数据痕迹。
在Javascript中,每当您想对发生的事情做出响应时,您必须将逻辑与对应于“正在发生的事情”的相关事件的处理程序绑定。在本例中,场景的相关部分是,您希望在用户单击某个元素时检查选择了哪些元素。在确定“click”是您要针对的事件之后,下一步是添加
onClick
处理程序

具体来说,您要做的是向所有三个元素添加一个
onClick
处理程序,该处理程序检查是否检查了其他两个元素(如果是,则创建所需的反馈)。例如,假设您有三个复选框,所有复选框都带有一个类“checkbox”:

-编辑-

由于您没有处理复选框(它们跟踪自己的状态),因此您需要跟踪是否以某种方式选择了每个
。幸运的是,jQuery提供了一种在元素上保存任意数据的机制,称为
data
。以下是您可以如何使用它:

$('#p26_opt1, #p26_opt2, #p26_opt3').click(function() {
     // check whether this div was selected already
     var wasSelected = $(this).data('selected');

     // change its selected state to the opposite of what it was before
     $(this).data('selected', !wasSelected);

     // keep track of whether any checkboxes are un-checked with a flag
     var anyUnselected;

 // iterate through all the divs
     $('#p26_opt1, #p26_opt2, #p26_opt3').each(function() {
         // if there was already an un-selected div, or if this div is
         // un-selected, set our flag
         anyUnselected = anyUnselected || !$(this).data('selected');
     });
     // if our flag indicates any were un-seelcted, stop here
     if (anySelected) return;

     // do whatever you want to do when all three are checked.
     $('#secondaryFeedbackStatement').show();
});

如果这正是您需要的。

向我们展示一些代码。不清楚你在问什么。听起来你在问“当多个输入被“选择”时(例如,当多个复选框被选中时),我怎么做X?”。正确吗?谢谢MachineHost我没有使用复选框。这里是它的外观定期检查存储在设备上的数据,以确定您不再需要什么。好的,首先,我建议编辑您的问题并添加这些信息;现在您的问题将因不清楚您的问题而关闭。第二节接下来,我更新了我的答案,以便更好地描述您的场景。事实上,我刚刚意识到您可能还没有编辑权限,所以我冒昧地为您更新了这个问题。另外,请注意:虽然您的场景依赖于literal
onClick
属性,但我连接
click
处理程序的方式(使用
$(…).click(…)
)被广泛认为是首选方法,因为内联Javascript很快就会变得难以维护。多亏了HC,我现在就尝试一下
$('#p26_opt1, #p26_opt2, #p26_opt3').click(function() {
     // check whether this div was selected already
     var wasSelected = $(this).data('selected');

     // change its selected state to the opposite of what it was before
     $(this).data('selected', !wasSelected);

     // keep track of whether any checkboxes are un-checked with a flag
     var anyUnselected;

 // iterate through all the divs
     $('#p26_opt1, #p26_opt2, #p26_opt3').each(function() {
         // if there was already an un-selected div, or if this div is
         // un-selected, set our flag
         anyUnselected = anyUnselected || !$(this).data('selected');
     });
     // if our flag indicates any were un-seelcted, stop here
     if (anySelected) return;

     // do whatever you want to do when all three are checked.
     $('#secondaryFeedbackStatement').show();
});
    var a = false
    var b = false
    var c = false

onclickA(){
     //general onclickA code
     a = true
     if (a && b && c){
        //execute your desired code  
     }
}

onclickB(){
     //general onclickBcode
     b = true
     if (a && b && c){
        //execute your desired code  
     }
}
onclickC(){
     //general onclickC code
     c = true
     if (a && b && c){
        //execute your desired code  
     }
}