<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
所以我遇到的问题是这个代码适用于个人笔记本电脑上的Internet Explorer,但不适用于Chrome。在我的uni计算机上,代码在chrome或Internet Explorer上根本不起作用。我试图通过代码寻找错位的括号,但还没有找到问题。这种情况以前发生过,问题是一个错位或缺失的括号。如果有人可以通过这个代码告诉我什么是错的或丢失了?
答案 0 :(得分:0)
这本身并不是答案,但这里有一些建议的改进,它们限制了重复的代码位数,并且没有任何全局变量。< / p>
/* This only operates on the element with id="entertext".
* You could easily rewrite the function to pass in an element to
* operate on. If no 3rd parameter is passed, it won't do anything if the
* style is not equal to the first.
*/
function toggleStyle(property,ifTrueValue,ifFalseValue){
var el = document.getElementById('entertext');
if( el.style[property] !== ifTrueValue )
el.style[property] = ifTrueValue;
else if (typeof ifFalseValue !== 'undefined')
el.style[property] = ifFalseValue;
}
}
function toggleBold(){
toggleStyle('fontWeight',700,200);
}
function toggleitalic(){
toggleStyle('fontStyle','italic','normal');
}
function toggleline() {
toggleStyle('textDecoration','underline','none');
}
function togglered() {
toggleStyle('color','red','black');
}
function toggleblue() {
toggleStyle('color','blue','black');
}
function togglegreen() {
toggleStyle('color','green','black');
}
function togglefontA(){
toggleStyle('fontFamily',"Impact,Charcoal,sans-serif")
}
function togglebfontB(){
toggleStyle('fontFamily',"Times New Roman, Times, serif");
}
function togglefontC(){
toggleStyle('fontFamily',"Agency FB, verdana, helvetica, sans-serif";
}
function togglefontD(){
toggleStyle('fontFamily',"Arial, Helvetica, sans-serif");
}
function rgb(){
var rgb = getRGB()
color;
if( rgb == false)
color = 'white';
else
color = "rgb("+rgb.red+","+rgb.green+","+rgb.blue+")";
toggleStyle('backgroundColor', color );
}
function getRGB(){
var red= document.getElementById("red").value;
var green= document.getElementById("green").value;
var blue= document.getElementById("blue").value;
if( red <= 255 && red >= 0 && green <= 255 && green >= 0 && blue <= 255 && blue >= 0 ) {
return {
'red': red,
'green': green,
'blue': blue
}
} else
return false;
}