表单form中的buttom元素不能执行onclick方法?

yycqly 2016-09-29 08:04:00

<body>
<form>
<button id="loginBtn" >登录</button>
</form>
</body>
<script>
document.getElementById("loginBtn").onclick=function(){
var a=9;
layer.alert(a);
};
</script>
...全文
338 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
霜月枫桥 2016-09-30
  • 打赏
  • 举报
回复
layer的使用需要下一个.js脚本,你看一下你下了吗,然后通过<script src="layer/layer.js"></script>引进来,要不然你无法使用layer。2楼的jQuery也需要下一个jQuery.js脚本,或者使用浏览器上的jQuery,否则你也无法使用。
十口月月 2016-09-29
  • 打赏
  • 举报
回复
亲测能用 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <body> <form> <button id="loginBtn" >登录</button> </form> </body> <script> document.getElementById("loginBtn").onclick=function(){ var a=9; alert(a); }; </script> </html>
I,Frankenstein 2016-09-29
  • 打赏
  • 举报
回复
用jQuery 多方便

$("#loginBtn").click(function(){
   alert("button点击")
});
试试吧

81,122

社区成员

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

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