单击时禁用/启用按钮

Disable/Enable Buttons when clicked

本文关键字:启用 按钮 单击      更新时间:2023-09-26

我有一组svg形状,有一个类&单独的id。我在这些形状上实现了一个onclick函数,它反过来运行另一个函数(filter),过滤掉画布内的数组。我也有一个双击返回过滤器数组。

但是,当我单击其中一个形状时,我希望其他形状被禁用,直到我双击刚刚单击的形状。我已经看到了很多例子,但似乎不工作在这里的工作,我到目前为止:

function filter (d) {

  if (d.s =='triangle')  
     {d3.selectAll(".nodes").filter(function(d) {return d.categ === 'High' || d.categ === 'Low'}).transition().style("opacity", 0).style("display", "none");
        d3.selectAll("#High").on('click',function() { d3.event.stopPropagation(); } ); }
else if (d.s =='cross')  
     {return d3.selectAll(".nodes").filter(function(d) {return d.categ === 'Medium' || d.categ === 'Low'}).transition().style("opacity", 0).style("display", "none");}
else {return d3.selectAll(".nodes").filter(function(d) {return d.categ === 'Medium' || d.categ === 'High'}).transition().style("opacity", 0).style("display", "none");}
   }   

function antifilter (d) {

      d3.selectAll(".nodes").transition().style("opacity", 1).style("display", "block")

 }

我也尝试使用

     .on('click',null)

      document.getElementById("High").onclick = function() { return false; }

但是运气不好。任何帮助都太好了!当我双击鼠标时,有没有办法让鼠标再次点击。找不到与stopPropagation相反的方法来重置我的过滤器

http://jsfiddle.net/yPqqx/

我刚刚尝试了一个关于你的问题的场景,看看

HTML

<span id="res">0</span>
<a href="javascript:void(0);" id="High">Link</a><br>
<a href="javascript:void(0);" id="Enable">Enable</a><br>
<a href="javascript:void(0);" id="Disable">Disable</a>
jQuery

function increase(){
    $("#res").text(parseInt($("#res").text()) + 1);
}
$("#High").on("click",increase);
//Enable
$(document).on("click","#Enable",function(){
    $("#High").on("click",increase);
});
//Disable
$(document).on("click","#Disable",function(){
    $("#High").off();
});

和jsFiddle