新手问个基础问题
- JScript code
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> function change() { document.bgColor = "red"; } </script></head><body><input type="text" name="color" id="color"/><input type="button" onclick="change(color)"/></body></html>怎么把第一个input的内容设置为可以输入颜色,
然后按button的时候实现改变背景颜色?
[解决办法]
CSS颜色关键字有N多呢,反正我是没想出来怎么判断数值合法,百度下CSS颜色表的代码,那样比较好做
- JScript code
<html><head></head><body><input type="text" name="color" id="color"/><input type="button" onclick="change()" value="确定"/></body><script>function change(){ var color_key=document.getElementById("color").value; document.body.style.backgroundColor=color_key;}</script></html>
[解决办法]
- HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> function change() { var color = document.getElementById("color").value; document.bgColor = color; } </script></head><body><input type="text" name="color" id="color"/><input type="button" onclick="change()"/></body></html>