w100224 2015-01-10 08:02 采纳率: 85.7%
浏览 2990
已采纳

为什么这段代码onClick无效啊

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'cart1.jsp' starting page</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">
        function jian() {
            alert(" ---");
        }
        function addd() {
            alert(" ++=");
        }
    </script>


  </head>

  <body>
    <form  method="post" >
        <table border=1 align="center">
            <tr>
                <td  colspan="4" align="center">订单</td>
            </tr>
            <tr>
                <td>商品</td>
                <td>数量</td>
                <td>总价</td>
            </tr>
            <tr>
                <td>aaa</td>
                <td><input type="button" name="jian" onClick="jian()" value="-"></button>
                    <input name="shuru" class="input_text" type="text" value="1" size="3">
                <button name="addd" onClick="addd()">+</button></td>
                <td><input name="cost" class="input_text" type="text" value="0" size="3"
                    value="0"></td>
            </tr>
            <tr>
                <td colspan="4" align="center">
                    <button id="buy_anniu" type="submit" onClick="but()">提交</button>
                    <button type="reset">重置</button>
                </td>
            </tr>
            </table>

    </form>
  </body>
</html>

  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2015-01-10 10:31
    关注

    不要用button标签,用input type='button',你用button标签再标准浏览器下是提交按钮,直接提交表单了,而且你的输入控件对象不要将name和你的函数名起一样,会导致在onclick引用到这个控件,而不是你的函数

               <tr>
                    <td>aaa</td>
                    <td><input type="button" onClick="jian()" value="-">
                        <input name="shuru" class="input_text" type="text" value="1" size="3">
                    <input type="button"  onClick="addd()" value="+"/></td>
                    <td><input name="cost" class="input_text" type="text" value="0" size="3"
                        value="0"></td>
                </tr>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题