Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript D3-工具提示内的按钮应根据选择颜色禁用_Javascript_Jquery_D3.js - Fatal编程技术网

Javascript D3-工具提示内的按钮应根据选择颜色禁用

Javascript D3-工具提示内的按钮应根据选择颜色禁用,javascript,jquery,d3.js,Javascript,Jquery,D3.js,我有一张通过D3生成的美国各州地图。绑定到每个县的事件之一是单击事件,该事件呈现工具提示覆盖,其中包含三个按钮。我想做的是根据单击选择的颜色禁用其中一个按钮 目前,如果我在Firebug中单步执行单击处理程序,则相应的按钮将被禁用,但如果未启用断点,则所有按钮都将被启用 我有一个模块变量thisObj,由 thisObj : { ... _fillColors : { market : "#0000ff", prospect : "#ff0000", neutr

我有一张通过D3生成的美国各州地图。绑定到每个县的事件之一是单击事件,该事件呈现工具提示覆盖,其中包含三个按钮。我想做的是根据单击选择的颜色禁用其中一个按钮

目前,如果我在Firebug中单步执行单击处理程序,则相应的按钮将被禁用,但如果未启用断点,则所有按钮都将被启用

我有一个模块变量
thisObj
,由

thisObj : {
  ...
  _fillColors : { 
    market : "#0000ff",
    prospect : "#ff0000",
    neutral : "#c0c0c0",
    hover : "#4CD550" 
  },
  ...
}
我将一个HTML模板设置为一个模块变量

thisObj._tooltip.template = "<div id = 'tooltip_template'>" + 
            "<div class = 'county_data'></div>" +
            "<img src = '/static/images/delete.png' width = '28' height = '28' class = 'delete_logo' id = 'close_tooltip' />" +
            "<div id = 'no_client_message'></div>" +
            "<button id = 'add_prospective_market' class = 'tooltip_button'>Prospective Market</button>" +
            "<button id = 'add_market' class = 'tooltip_button'>Market County</button>" +
            "<button id = 'remove_market' class = 'tooltip_button'>Remove Market</button></div>";
然后我检查是否进行了下拉选择。如果没有,则所有按钮都被禁用。否则,使用rgb2hex函数将背景色转换为十六进制,并进行比较

if (thisObj._currentClient.id == null) {
  $("#no_client_message").text("No client has been selected");
  $(".tooltip_button").button("disable");
}

else {
  var countyFillColor = rgb2hex($("#" + d.id).css("fill"));

  if (countyFillColor == thisObj._fillColors.market)
    $("#add_market").button("disable");

  if (countyFillColor == thisObj._fillColors.prospect)
    $("#add_prospective_market").button("disable");
}

//fade tooltip into view
thisObj._tooltip.tooltip
  .transition()
  .duration(800)
  .style("opacity", 1);

我的问题是,条件的第一部分通过禁用所有按钮按需工作,但选择性禁用在Firebug中单步执行之外不起作用。一次又一次,当我点击一个红色元素时,我看到手动点击Firebug中的行后,
add\u prospective\u market
按钮被禁用,但删除断点会导致所有按钮被启用。

您还没有向我们展示您的完整代码,但听起来,启用/禁用按钮的功能在不同的状态下执行了多次。因此,第一次执行时,一切正常,但随后的执行会发生变化。@Larskothoff,我把模块代码放在。如果有多个状态值相互覆盖,如何解决该问题?好的,代码太多了。你有没有试着在调试器中更进一步,看看之后是什么改变了状态?@Larskothoff好吧,相关的代码段在329行和380行之间,然后它返回D3代码库。当我在调试器中单步执行最后一行时,设置了启用/禁用状态,因此我认为这可能与由于D3事件优先级而跳过按钮设置代码块有关。
if (thisObj._currentClient.id == null) {
  $("#no_client_message").text("No client has been selected");
  $(".tooltip_button").button("disable");
}

else {
  var countyFillColor = rgb2hex($("#" + d.id).css("fill"));

  if (countyFillColor == thisObj._fillColors.market)
    $("#add_market").button("disable");

  if (countyFillColor == thisObj._fillColors.prospect)
    $("#add_prospective_market").button("disable");
}

//fade tooltip into view
thisObj._tooltip.tooltip
  .transition()
  .duration(800)
  .style("opacity", 1);