小白求助:为什么这样实现不了输入颜色后背景颜色的改变?

一脸懵逼的小白233 2019-06-21 05:40:06
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script language="JavaScript"> function color(c) { var a=this.form.text1.value; if(a=="red" ) {document.bgColor="red";} else if(a="blue") {document.bgColor="blue";} else if(a="yellow") {document.bgColor="yellow";} } </script> </head> <body> <form> <input type="text" value="请输入颜色" name="text1" /> <input type="button" value="确定" name="button" onclick="color()"/> </form> </body> </html>
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我也是耶,不过我要明年下半年才实习
wangChao_live 2019-06-22
  • 打赏
  • 举报
回复
我也是编程新手,还有半年才实习
  • 打赏
  • 举报
回复
非常感谢!!,解决了我的问题!
天际的海浪 2019-06-21
  • 打赏
  • 举报
回复
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script language="JavaScript"> function color(c) { var a=c.form.text1.value; if(a=="red" ) {document.bgColor="red";} else if(a=="blue") {document.bgColor="blue";} else if(a=="yellow") {document.bgColor="yellow";} } </script> </head> <body> <form> <input type="text" value="请输入颜色" name="text1" /> <input type="button" value="确定" name="button" onclick="color(this)"/> </form> </body> </html>
  • 打赏
  • 举报
回复
啊啊!!!原来是form没给命名,我自己解决啦!!

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧