2015-07-28 81 views
0

我有一个锚点标记,其中我通过JavaScript删除了href属性。 我也曾使用setAttribute来添加style="cursor:default;" 但仍然手指针正在悬停在文本上显示。 这是什么我在这里做错了。使用javascript将光标更改为锚点标记中的默认值

HTML

<li> 
<a class="menu-item" href="www.google.com" > 
<span>Link Text</span> 
</a> 
</li> 

JS

window.onload=function removeLink() 
{ 
menuItem.removeAttribute("href"); 
menuItem.setAttribute("style","cursor:default;"); 
} 

后页面加载HTML变成这样

<li> 
<a class="menu-item" style="cursor:default;" > 
<span>Link Text</span> 
</a> 
</li> 

当页面呈现这些变化是在T可见他的代码,但仍然我得到了悬停在链接上的手形指针

我已经尝试使用menuItem.style.cursor =“default”; 而且还试图通过CSS

CSS

.class a:hover{ 
cursor:default;} 
+0

尝试 'menuItem.style.cursor ='default'' – Rahul

+0

显示你的HTML代码也 –

+0

@Mike ...您好,我也加入了我的HTML。 –

回答

0

将其设置使用,如果你想改变的文件中体现setAttribute是不可靠的。使用Element.style代替:

menuItem.style.cursor='default'; 
+0

已经尝试过!我已经更新了这个问题 –

0

读到这里:Mouse Coursor 1Mouse Coursor 2

试试这个:

document.getElementById("anchor").style.cursor="default";
<a href="https://www.google.co.in" id="anchor">Google</a>