<script language="javascript">
function c(){
    return document.getElement('count').value;
         }
</script><input type="text" size="3" value="1" name="add"id="count" />
<a href="change.do?id=<%=id %>&value="+c() >更改数量</a>
我想在href的请求参数value后面拼上 input的value值 ,可是总是拼不成
http://localhost:8080/shoppingcard/change.do?id=1&value=
次为上段代码执行结果。求大神帮助,小弟刚上手菜鸟一个。JavaScript函数

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
    <title>无标题文档</title>
    <script type="text/javascript">
    jQuery(function($){
    $('#a').click(function(){
    var href=$(this).attr('href');
         href+=$('#count').val();
    alert(href);
    return false;
    });});
    </script>
    </head><body>
    <input type="text" size="3" value="1" name="add" id="count" />
    <a id="a" href="change.do?id=12&value=">更改数量</a>
    </body>
    </html>
      

  2.   

    纯JS<title>无标题文档</title></head><body><input type="text" size="3" value="1" name="add" id="count" />
    <a id="a" href="http://www.baidu.com/change.do?id=12&value=">更改数量</a><script type="text/javascript">
    document.getElementById('a').onclick=function(event){
    var e=(event.target)?event.target:event.srcElement;
    var href=e.href;
         href+=document.getElementById('count').value;
    alert(href);
    return false;
    };
    </script>
    </body>
    </html>