2013-08-28 40 views
0

我怎样才能用JavaScript一个TD元素添加样式属性cursor添加光标:手用JavaScript

我已经试过这样:

var tabla = document.getElementById("table"); 
var fila = document.createElement("tr"); 
var celda1 = document.createElement("td"); 
var estilo = document.createElement('style'); 

//I check the navigator 
var gko = navigator.userAgent.toLowerCase(); 

if (gko.indexOf('gecko') != -1) 
{ 
// All the rest navigators 
estilo.innerHTML = "td {cursor: pointer;}"; 
} 
else 
{ 
//IE navigator 
estilo.innerHTML = "td {cursor: hand;}"; 
} 

fila.appendChild(celda1); 
tabla.appendChild(fila); 

这适用于除了IE 9.0的所有导航仪。

回答

3

cursor: hand不会在IE9工作,因为cursor: pointer是做正确的方式。如果您需要支持IE5,只是包括在你的CSS文件,并摆脱你的JavaScript代码:

cursor: pointer; 
cursor: hand; 

否则,cursor: pointer;就足够了。无论哪种情况,您都不需要JavaScript。

+0

太谢谢你了。我认为光标:手是适用于所有版本IE的正确的systax,但对于光标:指针可以正常工作。再次感谢。 – user2588156