0
在我的页面中,我使用JavaScript功能块与条件。如果浏览器是IE8,那么样式将如此,或者在其他样式中使用样式。但是,如果我使用下面的条件,该功能不起作用。请人帮我解决这个问题检查功能内的浏览器类型不工作在Javascript
function addnew(type)
{
type=parseInt(type)+1;
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true);
var mydiv = document.createElement("div");
mydiv.setAttribute("id",name5);
if(!IE){
mydiv.setAttribute("style","width:110px;height:80px;background-image:url(images/transparent.png);float:left;text-align:center;border:1px solid #ccc;");
}
else
{
mydiv.style.setAttribute('cssText', "width:110px;height:80px;background-image:url(images/transparent.png);float:left;text-align:center;border:1px solid #ccc;");
}
}
<input id="addchoice" type=button value="Add New Entry" onclick="addnew(document.forms['addpoll']['choicecount'].value);">
究竟错在何处? IE变量来自哪里? –
var isOpera,isIE = false;如果(typeof(window.opera)!='undefined'){isOpera = true;} if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true);在页面的顶部 – Rithu
但我有一个JavaScript函数,其中包含包含多个变量的长编码。例如http://jsfiddle.net/3Sd4W/ 这是我的代码,我必须更改每个支持IE8和Chrome的变量。任何想法。在那个addnew函数中,IE8不支持onclick,class,setattribute和其他一些东西 – Rithu