点击按钮没有反应,onclick函数点击无反应的原因

今天写代码的时候,有一个按钮onclick函数一直点击无反应,用alert去调试也依然跳不出来,说明根本没有调用,后来发现是这个原因:

<input type="button" οnclick="close()" >

方法名是close()。可能与某些关键词冲突,换一个名字或者加个123以示区别就行。有时有些浏览器反而没问题,不过还是尽量避开关键词关键标签等的好。

这个原因是在网上找到的,可以点击这里https://www.imooc.com/article/11273

新知识get!

转载于:https://www.cnblogs.com/wwHww/p/9049907.html

发布了0 篇原创文章 · 获赞 0 · 访问量 713
展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

button单击不能触发事件

03-14

button单击没任何反应,直接不触发事件。什么原因呢?? jsp编码 ``` <%@ 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> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Login Page</title> <style type="text/css">@IMPORT url("css/m.css");</style> <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script> <script type="text/javascript" src="js/login.js"></script> </head> <body> <br><br><br><br> <div class="back"> <div> <fieldset> <legend>JobSite</legend> <div class="content"> <p> <label for="tel">手机号码:</label> <input type="text" id="tel" name="tel" tabindex="1"> </p> <p> <label for="psw">你的密码:</label> <input type="password" id="psw" name="psw" tabindex="2"> </p> <a href="/JobSite0/index.html" >返回主页面</a> <a href="forget" title="Forget password">忘记密码</a> <p> <input type="button" tabindex="4" value="学生登录" id="btn1"> <input type="button" tabindex="5" value="公司登录" id="btn2"> </p> </div> </fieldset> </div> </div> </body> </html> ``` javascript编码 ``` function $$(id){ return document.getElementById(id); } $("#btn1").click(function(){ alert("学生的登录"); $.ajax({ type:"POST", url:"/JobSite0/test", data:{"tel":$$("tel").value,"psw":$$("psw").value}, success:function(result){ if(result=="true"){ location.replace("http://localhost:8888/JobSite0/student"); }else{ alert("你的用户名或密码错误!"); } } }); }); $("#btn2").click(function(){ $.ajax({ type:"POST", url:"/JobSite0/test_c", data:{"tel":$$("tel").value,"psw":$$("psw").value}, success:function(result){ if(result=="true"){ location.replace("/JobSite0/company"); }else{ alert("你的用户名或密码错误!"); } } }); }); ``` 问答

Ajax点击按钮没有反应

07-23

test.jsp <%@ page contentType="text/html;charset=GB2312"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>AJAX提交请求测试页面</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="js/jquery-1.8.0.js"></script> <script type="text/javascript" src="js/json.js"></script> </head> <script language="javascript"> $(document).ready(function(){ $("#btn").click(function(){ $.ajax({ url: "AjaxEventHandleAction", type: "POST", data: {"AppCode":"50201A","DataSets":"2","Datas":"[{'name':'jim','age':'20'},{'name':'jim','age':'20'}]"}, dataType: "json", success:function(data) { var jsonStr = eval("("+data+")"); //alert(data); document.getElementById("info").innerHTML = "retAppCode: [ "+jsonStr.retAppCode+" ] DataSets: [ "+jsonStr.retDataSets+" ] 信息:[ "+jsonStr.retDatas[0].info+" ] "; //alert("success:OperCode="+jsonStr.OperCode); //alert("success:DataSets="+jsonStr.DataSets); //alert("success:Datas[0].name="+jsonStr.Datas[0].name); //alert("success:Datas[0].age="+jsonStr.Datas[0].age); }, error:function(data) { alert("error:"); } }); }); }); </script> <body> <div id="info"></div> <s:submit value="%{getText('test')}" id="btn"/> </body> </html> Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>welcome.html</welcome-file> <welcome-file>login.html</welcome-file> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>com.essa.config.InitSys</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/error.jsp</location> </error-page> <error-page> <exception-type>401</exception-type> <location>/error.jsp</location> </error-page> <error-page> <exception-type>500</exception-type> <location>/error.jsp</location> </error-page> </web-app> Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <include file="struts-default.xml"/> <package name="essa" extends="json-default"> <interceptors> <interceptor name="essaBoundaryInterceptor" class="com.essa.Interceptor.essaBoundaryInterceptor"> <param name="filterURISwitch">/welcome.html;/login;/html/help;</param> </interceptor> <interceptor-stack name="essaDefaultStack"> <!-- interceptor-ref name="json" /--> <interceptor-ref name="essaBoundaryInterceptor" /> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> <default-interceptor-ref name="essaDefaultStack" /> <default-action-ref name="DefaultAction" /> <global-results> <result name="failPage" type="redirect">/login.jsp</result> </global-results> <action name="DefaultAction" class="com.essa.action.DefaultAction"> <result name="LoginFail" type="redirect">/LoginFail.html</result> </action> <action name="AjaxEventHandleAction" class="com.essa.action.AjaxEventHandleAction"> <result type="json"><param name="root">result</param></result> </action> <action name="LoginAction" class="com.essa.action.LoginAction"> <result name="LoginOK" type="dispatcher">/website/home.jsp</result> <result name="LoginFail" type="redirect">/LoginFail.html</result> <result name="Normal" type="redirect">/welcome.html</result> <result name="Help" type="dispatcher">/html/help/help.html</result> </action> <!-- 当调用具体的分值结转申请、异议申请等后台执行转长的生成文件,静态化等时,先生成等待进度条,配置一个createStaticsESLFileAction,配置<interceptor-ref name="execAndWait"拦截器>注释 --> </package> <constant name="struts.i18n.encoding" value="UTF-8" /> <constant name="struts.action.extension" value="action"/> </struts> Action: package com.essa.action; import java.io.IOException; import net.sf.json.JSONObject; import org.apache.log4j.Logger; import com.essa.util.DealRequest; import com.essa.util.VertifyRequest; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; /** * @name EssaAction * @time 2015-06-20 * @version 1.0.0 * @author ZhangDongxu */ public class AjaxEventHandleAction extends ActionSupport { private static Logger logger = Logger.getLogger(AjaxEventHandleAction.class.getName()); private static final long serialVersionUID = 1L; private String result; private String AppCode ; private String DataSets ; private String Datas ; private int res = 999; public String getResult() { return result.trim(); } public void setResult(String result) { this.result = result.trim(); } public String getAppCode() { return AppCode.trim(); } public void setAppCode(String appCode) { AppCode = appCode.trim(); } public String getDataSets() { return DataSets.trim(); } public void setDataSets(String dataSets) { DataSets = dataSets.trim(); } public String getDatas() { return Datas.trim(); } public void setDatas(String datas) { Datas = datas.trim(); } public String execute(){ logger.info(">>>>>> [请求信息:AppCode = <"+AppCode+">,DataSets = <"+DataSets+">,Datas = <"+Datas+">]"); try { res = VertifyRequest.vertifyRequest(AppCode,DataSets,Datas); } catch (IOException e) {} if(res!=0){ logger.info(">>>>>> [请求校验失败:res = <"+res+">]"); result = VertifyRequest.getErrorResult(AppCode,res,Datas); } else{ logger.info(">>>>>> [请求校验成功:res = <"+res+">]"); result = DealRequest.getResult(AppCode,DataSets,Datas); } result = JSONObject.fromObject(result).toString(); return SUCCESS; } } /* * // ActionContext ac = ActionContext.getContext(); // String rand = ac.getSession().size()+""; System.out.println(name+pwd); Datas = "[{'name':'"+name+"','pwd':'"+pwd+"'}]"; System.out.println(Datas); logger.info(">>>>>> [锟斤拷锟斤拷锟斤拷息锟斤拷AppCode = <"+AppCode+">,DataSets = <"+DataSets+">,Datas = <"+Datas+">]"); try { res = VertifyRequest.vertifyRequest(AppCode,DataSets,Datas); } catch (IOException e) {} if(res!=0){ logger.info(">>>>>> [锟斤拷锟斤拷校锟斤拷失锟杰o拷res = <"+res+">]"); result = VertifyRequest.getErrorResult(AppCode,res,Datas); } else{ logger.info(">>>>>> [锟斤拷锟斤拷校锟斤拷晒锟斤拷锟絩es = <"+res+">]"); result = DealRequest.getResult(AppCode,DataSets,Datas); } result = JSONObject.fromObject(result).toString(); return "LoginOK"; */ 可以直接访问Action但是通过Ajax点击按钮访问的时候就没有访问 这个是拦截器: package com.essa.Interceptor; import org.apache.log4j.Logger; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; /** * @name MyInterceptor * @time 2015-06-20 * @version 1.0.0 * @author ZhangDongxu */ public class essaBoundaryInterceptor implements Interceptor { private static Logger logger = Logger.getLogger(essaBoundaryInterceptor.class.getName()); /** * 自定义拦截器执行的代码 * 作用:拦截请求 * */ private static final long serialVersionUID = 1L; public void destroy() {} public void init() {} public String intercept(ActionInvocation invocation) throws Exception { logger.info(">>>>>> [请求信息:执行了自定义拦截器的代码!!!!]"); return invocation.invoke(); } } 非常感谢 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览