<html>
<head>
<title>seting color preference</title>
<script language="JavaScript"><!--
function nameDefined(c,n){
var s=removeBlanks(c)
var pairs=s.split(";")
for(var i=0;i<pairs.length;++i){
var pairSplit=pairs[i].split("=")
if(pairSplit[0]==n)return true
}
return false
}
function removeBlanks(s){
var temp=" "
for(var i=0;i<s.length;++i){
var c=s.charAt(i)
if(c!=" ")temp+=c
}
return temp
}
function getCookieValue(c,n){
var s=removeBlanks(c)
var pairs=s.split(";")
for(var i=0;i<pairs.length;++i){
var pairSplit=pairs[i].split("=")
if(pairSplit[0]==n)return pairSplit[1]
}
return ""
}
function readCookie(){
var cookie=document.cookie
background="white"
text="black"
if(nameDefined(cookie,"background"))
background=getCookieValue(cookie,"background")
if(nameDefined(cookie,"text"))
text=getCookieValue(cookie,"text")
}
function setCookie(){
var newCookie="background="+background
newCookie+=";expires=Wednesday,09-NOV-99 23:12:40 GMT"
window.document.cookie=newCookie
var newCookie="text="+text
newCookie+=";expires=Wednesday,09-NOV-99 23:12:40 GMT"
window.document.cookie=newCookie
window.location="prefs.htm"
}
function prefsForm(){
document.writeln('<FROM name="prefs">')
document.writeln('Background color:')
document.writeln('<SELECT name="bg" size="1">')
document.writeln('<option>black')
document.writeln('<option SELECTED>white')
document.writeln('<option>red')
document.writeln('<option>orange')
document.writeln('<option>yellow')
document.writeln('<option>green')
document.writeln('<option>blue')
document.writeln('<option>brown')
document.writeln('</SELECT>')
document.writeln('Text color:')
document.writeln('<SELECT name="fg"> size="1">')
document.writeln('<option SELECTED>black')
document.writeln('<option>white')
document.writeln('<option>red')
document.writeln('<option>orange')
document.writeln('<option>yellow')
document.writeln('<option>green')
document.writeln('<option>blue')
document.writeln('<option>brown')
document.writeln('</SELECT>')
document.writeln('<input type="button" value="set Colors" onClick="setPerfs()">')
document.writeln('</FORM>')
}
function setPerfs(){
bgField=window.document.prefs.bg
bgIndex=bgField.selectedIndex
background=bgField.options[bgIndex].text
fgField=window.document.prefs.fg
fgIndex=fgField.selectedIndex
text=fgField.options[fgIndex].text
setCookie()
}
readCookie()
document.bgColor=background
document.fgColor=text
//--></script>
</head>
<body BGCOLOR="#FFFFFF">
<script language="JavaScript"><!--
prefsForm()
//--</script>
<h ALIGN="center">seting color preference</h>
<p ALIGN="center">[the rest of the web page goes here]
</body>
</html>
怎么设置不了颜色啊 我是看书抄的
}
<head>
<title>seting color preference</title>
<script language="JavaScript"><!--
function nameDefined(c,n){
var s=removeBlanks(c)
var pairs=s.split(";")
for(var i=0;i<pairs.length;++i){
var pairSplit=pairs[i].split("=")
if(pairSplit[0]==n)return true
}
return false
}
function removeBlanks(s){
var temp=" "
for(var i=0;i<s.length;++i){
var c=s.charAt(i)
if(c!=" ")temp+=c
}
return temp
}
function getCookieValue(c,n){
var s=removeBlanks(c)
var pairs=s.split(";")
for(var i=0;i<pairs.length;++i){
var pairSplit=pairs[i].split("=")
if(pairSplit[0]==n)return pairSplit[1]
}
return ""
}
function readCookie(){
var cookie=document.cookie
background="white"
text="black"
if(nameDefined(cookie,"background"))
background=getCookieValue(cookie,"background")
if(nameDefined(cookie,"text"))
text=getCookieValue(cookie,"text")
}
function setCookie(){
var newCookie="background="+background
newCookie+=";expires=Wednesday,09-NOV-99 23:12:40 GMT"
window.document.cookie=newCookie
var newCookie="text="+text
newCookie+=";expires=Wednesday,09-NOV-99 23:12:40 GMT"
window.document.cookie=newCookie
window.location="prefs.htm"
}
function prefsForm(){
document.writeln('<FROM name="prefs">')
document.writeln('Background color:')
document.writeln('<SELECT name="bg" size="1">')
document.writeln('<option>black')
document.writeln('<option SELECTED>white')
document.writeln('<option>red')
document.writeln('<option>orange')
document.writeln('<option>yellow')
document.writeln('<option>green')
document.writeln('<option>blue')
document.writeln('<option>brown')
document.writeln('</SELECT>')
document.writeln('Text color:')
document.writeln('<SELECT name="fg"> size="1">')
document.writeln('<option SELECTED>black')
document.writeln('<option>white')
document.writeln('<option>red')
document.writeln('<option>orange')
document.writeln('<option>yellow')
document.writeln('<option>green')
document.writeln('<option>blue')
document.writeln('<option>brown')
document.writeln('</SELECT>')
document.writeln('<input type="button" value="set Colors" onClick="setPerfs()">')
document.writeln('</FORM>')
}
function setPerfs(){
bgField=window.document.prefs.bg
bgIndex=bgField.selectedIndex
background=bgField.options[bgIndex].text
fgField=window.document.prefs.fg
fgIndex=fgField.selectedIndex
text=fgField.options[fgIndex].text
setCookie()
}
readCookie()
document.bgColor=background
document.fgColor=text
//--></script>
</head>
<body BGCOLOR="#FFFFFF">
<script language="JavaScript"><!--
prefsForm()
//--</script>
<h ALIGN="center">seting color preference</h>
<p ALIGN="center">[the rest of the web page goes here]
</body>
</html>
怎么设置不了颜色啊 我是看书抄的
}
解决方案 »
- 想做个图片效果,求助。
- 在onmousemove后,onmouseup不起作用,请大家帮忙!
- 求助,关于javascript打开新窗口
- 求一个超简单的动作,不过要支持标准
- 如何用JAVASCRIPT进行如下CHECK
- 多文件上传,如何添加删除网页对象阿,急等,拜托
- 关于数据返回格式,请指教
- 如何把一个层显示在最顶端????
- 如何在页面上设置ie中的ActiveX安全属性.(automation服务器不能创建对象)
- 各位高手请看下面的代码如何添加到asp的代码中?谢谢!!!
- 谁有可以播放网络任务的js网页播放器代码呢,mp3的和MP4/flv的都需要。能给个网址下载么或者发我邮箱。
- 如何判断iframe是否加载完全?
其次你目前的代码报错 所以不能执行
比如 下面的元素就会取不到 你的元素都没有命名
bgField=window.document.prefs.bg
其次 语句都没用;结束 所以换行的地方就要小心了
比如
document.writeln('<input type="button" value="set Colors" onClick="setPerfs()">')
可能你的浏览器不支持这个DOM对象。