当前位置: 代码迷 >> Java Web开发 >> 不知道哪里有错?点击按钮运行script中的内容
  详细解决方案

不知道哪里有错?点击按钮运行script中的内容

热度:1694   发布时间:2013-02-25 21:11:32.0
不知道哪儿有错?点击按钮运行script中的内容
<body>
<script language="javascript" type="text/javascript">
<!-- 
var btn = document.getElementById("btn");
btn.onclick=test;

function changeBgColor(color) {
document.bgColor = color;
}

function test() {
var color = prompt("请输入颜色名称或颜色代码:", "");
changeBgColor(color);
}

//-->
</script>
   
  <input type="button" value="test" id="btn"/><br/>
</body>

------解决方案--------------------------------------------------------
为啥不在input上直接加onclick事件?你整到js里不是没事找事吗。<input type="button" value="test" id="btn" onclick = "test()"/>
你上面写的也不行,test是方法,要加这样test()
------解决方案--------------------------------------------------------
为什么不在input标签内写onclick事件。。。
------解决方案--------------------------------------------------------
这种属于js犯抽,你把所有的js代码移动到<body></body>的后面试试,应该能行
  相关解决方案