Javascript 如何使用querySelectorAll选择删除元素的某些属性?
我在这里得到了正确的元素,当我查看样式时,属性没有被删除,我的方法错了吗?我如何正确地做它?谢谢Javascript 如何使用querySelectorAll选择删除元素的某些属性?,javascript,highcharts,Javascript,Highcharts,我在这里得到了正确的元素,当我查看样式时,属性没有被删除,我的方法错了吗?我如何正确地做它?谢谢 var axes = document.querySelectorAll('.highcharts-axis-labels'); for (var i = 0; i < axes.length; i++) { if (i == 1) { axes[i].removeAttribute("position");
var axes = document.querySelectorAll('.highcharts-axis-labels');
for (var i = 0; i < axes.length; i++) {
if (i == 1) {
axes[i].removeAttribute("position");
axes[i].removeAttribute("height");
axes[i].removeAttribute("top");
axes[i].removeAttribute("width");
axes[i].removeAttribute("left");
axes[i].removeAttribute("margin-top");
//axes[i].css('margin-top', '0px');
}
var axes=document.querySelectorAll('.highcharts-axis-labels');
对于(变量i=0;i
.removeAttribute()
用于删除html元素的属性
乙二醇
在html上(
)
JS
document.getElementById('test').removeAttribute('data-test');
document.getElementById('test').removeAttribute('style');
您正在寻找的是删除样式属性,因此
document.getElementById('test').style.width="";
更新,查看您的q,您可能希望删除所有样式。如果是这样的话- 乙二醇 在html上(
test
)
JS
document.getElementById('test').removeAttribute('data-test');
document.getElementById('test').removeAttribute('style');
removeAttribute函数将只删除元素html中存在(或将存在)的内容。也就是说,如果元素应用了css规则,此函数将不会影响css-您需要更改元素的类、id或(更彻底地)更改应用于元素的css规则,或者简单地向元素添加内联样式以覆盖css。Rob的回答很好地解释了
removeAttribute
的功能。删除属性的目的是什么?不,很抱歉误导您,但我想删除style.css文件中的一些属性,而不是html中的属性,所发生的事情是在high中图表,highcharts轴标签指的是y轴标签和x轴标签,我为x轴设置了一些属性,现在y轴受到影响,不应该受到影响,这就是我想要删除的。我尝试了轴[I]。currentStyle.top=“0px”;但也不起作用。这是在IE8中,我很难在IE8中解决这个问题。如果是在css中,那么改为更改类如何…axes[I]。className='differenticsclass
?是的!这就是我在删除属性似乎无效时所做的,现在一切都正常了!谢谢