问题描述:
设置两个程序(下面的两个程序都不能执行,请兄弟们修改一下),分别用select对象和radio对象对网页背景颜色进行设置:
一:当选择列表中的一种颜色后,网页颜色自动变为所选定的颜色
<>
<head>
<script>
function showbgcolor1(){
document.bgcolor=document.form2.radio1.value}
</script>
</head>
<body>
<form name=form1 method="post" action="">请在列表筐中选择你喜欢的背景颜色:<br>
<select name=select1 onchange="document.bgcolor=this.options[this.selectedindex].value">
<option value="green" selected>green
<option value="blue">blue
<option value="red">red
</select>
</form>
</body>
</>
二:当选择一个单选按钮后,网页的颜色变为所选择的颜色
<>
<head>
<script>
function showbgcolor1(){
document.bgcolor=document.form2.radio1.value}
</script>
</head>
<body>
<form name=form2>请在单选按纽中选择你喜欢的背景颜色:<br>
<input type=radio name=radio1 value="red" onclick="showbgcolor1()">red
<input type=radio name=radio1 value="green" onclick="showbgcolor1()">green
<input type=radio name=radio1 value="blue" onclick="showbgcolor1()">blue
</form>
</body>
</>
解析:
1 )
<>
<body bgcolor="">
<form name=form1 method="post" action="">请在列表筐中选择你喜欢的背景颜色:<br>
<select name=select1 onchange="body.bgColor=this.options[this.selectedIndex].value">
<option value="green" selected>green
<option value="blue">blue
<option value="red">red
</select>
</form>
</body>
</>
2 )
<>
<head>
<script>
function showbgcolor1( color ){
document.body.bgColor= color
}
</script>
</head>
<body>
<form name=form2>请在单选按纽中选择你喜欢的背景颜色:<br>
<input type=radio name=radio1 value="red" onclick="showbgcolor1(this.value)">red
<input type=radio name=radio1 value="green" onclick="showbgcolor1(this.value)">green
<input type=radio name=radio1 value="blue" onclick="showbgcolor1(this.value)">blue
</form>
</body>
</>
这样的有几种写法,一个就是发送请求给后台,传的数据是邮箱,然后获取用户名,域名,顶级域名,然后渲染到页面上,但是这得后台配合,第二个就是自己声明假的数据,就是一个数组,里面有多个对象,比如:<input type="text" placeholder="请输入邮箱">
<button>开始分析</button>
<div>
用户名:<span class="username"></span></br>
域名:<span class="domain"></span></br>
顶级域名:<span class="top-domain"></span>
</div>
<script type="text/javascript">
var arr = [{email:"xx@163.com",username:"zhangsan",domain:"hao123",topDomain:".com"},{email:"yy@qq.com",username:"lisi",domain:"baidu",topDomain:".com"},{email:"zz@msn.com",username:"wangwu",domain:"taobao",topDomain:".com"}]
var inp = document.getElementsByTagName("input")[0]
var btn = document.getElementsByTagName("button")[0]
var username = document.getElementsByClassName("username")[0]
var domain = document.getElementsByClassName("domain")[0]
var topDomain = document.getElementsByClassName("top-domain")[0]
btn.onclick = function() {
var val = inp.value
username.textContent = ""
domain.textContent = ""
topDomain.textContent = ""
for (var i=0i<arr.lengthi++) {
if (val == arr[i].email) {
username.textContent = arr[i].username
domain.textContent = arr[i].domain
topDomain.textContent = arr[i].topDomain
}
}
}
</script>