【问题标题】:How to hide an element using javascript如何使用javascript隐藏元素
【发布时间】:2015-09-01 15:55:38
【问题描述】:

如何隐藏图表上的日期

<div class="highcharts-container" id="highcharts-6">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1330"   height="532"><desc>Created with Highstock 1.3.7</desc><defs><clipPath id="highcharts-7"><rect fill="none" x="0" y="0" width="1239" height="290"></rect></clipPath></defs>
<path fill="none" d="M 71 45 L 71 335 180 335 180 45" zIndex="5"></path>
<text x="126" y="29" transform="translate(0,0)" visibility="visible">
<tspan x="126">7/9/15</tspan></text></svg></div>

【问题讨论】:

  • 不会有太大不同:stackoverflow.com/questions/9872947/…
  • 我尝试了很多选项,但没有任何效果,请帮助
  • “我尝试了很多选择”。你向我们展示你的尝试怎么样?
  • $('tspan').remove() 完全删除它并清空tspan 只需使用$('tspan').html('')
  • 为什么不能为 point 设置空值?然后点将为空;)

标签: javascript jquery highcharts


【解决方案1】:

如果只有一个,那么这段代码应该可以工作:

document.querySelector("tspan").style.display = "none";

如果有多个则:

[].forEach.call(document.querySelectorAll("tspan"), function(item) {
  item.style.display = "none";
});

或者如果你想使用 jQuery:

$("tspan").hide();

【讨论】:

  • 有多个 tspan。我没有复制整个代码
  • 我试过了,但没用 $('div.highcharts-container > svg > text').find('tspan').html("");
  • 戴夫,我可以这样做
  • $('div.highcharts-container > svg > text').forEach.call(document.querySelectorAll("tspan"), function(item) { item.style.display = "none" ; });
  • 如果您使用的是 jQuery,请使用我回答中的最后一行——不要过于复杂。
猜你喜欢
  • 1970-01-01
  • 2015-02-28
  • 2018-01-05
  • 1970-01-01
  • 2017-03-13
  • 2021-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多