错误的写法


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>根据下拉框选中的值修改背景颜色</title>
<script type="text/javascript">
function changecolo(colo){//要有返回值
var color=colo.value;

alert(color)
if(color="red"){
document.bgcolor="#FF0000"
}
if(color="yellow"){
document.bgcolor="#FFFF00"
}
if(color="green"){
document.bgcolor="#00FF00"
}
if(color="blue"){
document.bgcolor="#0000FF"
}
else{
document.bgcolor="#FFFFFF"
}
}
</script>
</head>

<body>
<form name="form1">
<select id="colo" onChange="changecolo(this)">
<option value="red">红色</option>
<option value="yellow">黄色</option>
<option value="green">绿色</option>
<option value="blue">蓝色</option>
</select>
</form>
</body>
</html>


纠正后

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>根据下拉框选中的值修改背景颜色</title>
<script type="text/javascript">
function changecolor(colo){
var color=colo.value
alert(color)
document.bgColor=color
}
</script>
</head>

<body>
<form name="form1">
<select id="colo" onChange="changecolor(this)">
<option value="red">红色</option>
<option value="yellow">黄色</option>
<option value="green">绿色</option>
<option value="blue">蓝色</option>
</select>
</form>
</body>
</html>


或者用document.getElementById()做

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>根据下拉框选中的值修改背景颜色</title>
<script type="text/javascript">
function changecolor(){
var color=document.getElementById('colo').value

alert(color)
document.bgColor=color
}
</script>
</head>

<body>
<form name="form1">
<select id="colo" onChange="changecolor()">
<option value="red">红色</option>
<option value="yellow">黄色</option>
<option value="green">绿色</option>
<option value="blue">蓝色</option>
</select>
</form>
</body>
</html>

html根据下拉框选中的值修改背景颜色的更多相关文章

  1. 【jquery】ajax 动态 改变 select下拉框选中的值

    //JS<script type="text/javascript> //ajax动态给添加原料的[商品名称]下拉框绑定selected属性 $("#origin_co ...

  2. C# Winform 获得下拉框 选中的值

    string PrintName = cmbPrinter.SelectedIndex.ToString(); PrintName = cmbPrinter.SelectedItem.ToString ...

  3. JavaScript如何获得Select下拉框选中的值

    js代码: var mySelect = document.getElementById("resultList2"); var mySelectText = mySelect.o ...

  4. js,jquery获取下拉框选中的option

    js获取select选中的值: var sel=document.getElementById("select1"); var index = sel.selectedIndex; ...

  5. js 设置下拉框的默认值

    设置下拉框的默认值,直接在option中增加selected就可以了.但是现在要使用JS来设置它的默认值,代码如下: <select name="aaa" id=" ...

  6. jQuery操作下拉框的text值和val值

    jQuery操作下拉框的text值和val值 1,JS源码 <select name="select1" id="select1" style=" ...

  7. python+webdriver,选取Select下拉框中的值

    在选择下拉框中的值时遇到了困难,用driver.find_element_by_id("").send_keys("")进行赋值不能成功获取下拉框中的值.   ...

  8. Python3.x:遍历select下拉框获取value值

    Python3.x:遍历select下拉框获取value值 Select提供了三种选择方法: # 通过选项的顺序,第一个为 0 select_by_index(index) # 通过value属性 s ...

  9. LayUI中select下拉框选中触发事件

    代码: var form = layui.form, layer = layui.layer; // 监听 $(document).ready(function() { // select下拉框选中触 ...

随机推荐

  1. 如何利用 Webshell 诊断 EDAS Serverless 应用

    本文主要介绍 Serverless 应用的网络环境以及 Serverless 应用容器内的环境,了解背景知识以及基本的运维知识后可以利用 Webshell 完成基本的运维需求. Webshell 简介 ...

  2. 使用pstack和gdb调试死锁

    1:代码 下面是一个简单的能够发生死锁的代码: #include <unistd.h> #include <pthread.h> #include <string.h&g ...

  3. iOS UIWebView URL拦截

    http://www.cocoachina.com/ios/20150626/12161.html 本文译者:candeladiao,原文:URL filtering for UIWebView on ...

  4. Python进阶04函数的参数对应

    我们已经接触过函数(function)的参数(arguments)传递.当时我们根据位置,传递对应的参数.我们将接触更多的 参数传递方式. 回忆一下位置传递: def f(a,b,c): return ...

  5. 最优化方法系列:Adam+SGD-AMSGrad 重点

    https://blog.csdn.net/wishchin/article/details/80567558 自动调参的Adam方法已经非常给力了,不过这主要流行于工程界,在大多数科学实验室中,模型 ...

  6. H3C-PPPOE

    --------------pppoe拨号V7------------------------------- dialer-group 10 rule ip permit interface Dial ...

  7. 请求(RequestInfo)

    请求类型 StringRequestInfo 用在 SuperSocket 命令行协议中. 你也可以根据你的应用程序的需要来定义你自己的请求类型. 例如, 如果所有请求都包含 DeviceID 信息, ...

  8. js切割字符串

    var time_str= '2019-9-10 13:18:20'; var t = time_str.substr(2,8);   console.log(t);   输出  19-9-10

  9. Jieba分词包(一)——解析主函数cut

    1. 解析主函数cut Jieba分词包的主函数在jieba文件夹下的__init__.py中,在这个py文件中有个cut的函数,这个就是控制着整个jieba分词包的主函数.    cut函数的定义如 ...

  10. H3C ISDN网络构成