<a href=caxh/down_execgyload?page=1&jgm='+choice1+'&sh='+choice2+'>查看数据</a> choice1和choice2是javascript中的变量,但是以上写法变量值传递不了,如何解决?谢谢大家!

解决方案 »

  1.   

    你看看请求出来的URL是什么,贴出来
      

  2.   

    楼主您好,js不是php哦,您要在HTML里面使用首先您要使用script标签,而且如果您要动态改href的话为什么不咋js里面修改a的href属性呢,得到a的对象修改就可以了
      

  3.   

    你这段html是用js插入的,还是在html中写好的?
      

  4.   

    你外层掉了双引号吧
    <a href=“caxh/down_execgyload?page=1&jgm='+choice1+'&sh='+choice2+'”>查看数据</a> 
      

  5.   

    在html中写好的,我想直接引用js中的变量
      

  6.   

    “您要在HTML里面使用首先您要使用script标签,而且如果您要动态改href的话为什么不咋js里面修改a的href属性呢,得到a的对象修改就可以了 ” 不是特别理解,可以举个例子吗?谢谢了!
      

  7.   

    <script type="text/javascript">
    var choice1 = "111";
    var choice2 = "222";
    </script>
    方法一:修改a的href属性
    <a id="aaa">查看数据</a> 
    <script type="text/javascript">
    document.getElementById("aaa").href='caxh/down_execgyload?page=1&jgm='+choice1+'&sh='+choice2;
    </script>
    方法二:用document.write()
    <script type="text/javascript">
    document.write('<a href=caxh/down_execgyload?page=1&jgm='+choice1+'&sh='+choice2+'>查看数据</a>');
    </script>
      

  8.   

    如果不是a标签,而是input,并且随着参数值的改变而刷新当前页面,如何实现呢?
      

  9.   

    <input type="text" id="a">
    <input type="text" id="b">
    <input type="button" id="btn" onclick="btnClick()" value="确定">
    <input Type="Text" id="aaa" style="width:500px">
    <script type="text/javascript">
        function btnClick(){
    var choice1 = document.getElementById("a").value;
    var choice2 = document.getElementById("b").value;
    document.getElementById("aaa").value='caxh/down_execgyload?page=1&jgm='+choice1+'&sh='+choice2;
    }
    </script>
    没太看懂,不知道是不是你想要的
      

  10.   


    前两个input里输入内容,点确定按钮,最后一个input里输出你要的内容
      

  11.   

    试一下吧:<input type="button" id="button"  value=" 点击 ">
    <script type="text/javascript">
    document.getElementById('button').onclick=function(){
      location.href='http://'+location.host+'/caxh/down_execgyload?                page=1&jgm='+choice1+'&sh='+choice2;
    }
    </script>至于根据参数值改变而刷新,具体还要看参数值是怎么变的~
      

  12.   

    上面‘caxh/down_execgyload?                page’多输出了些空格,去掉再试~
      

  13.   

    试一下吧:<input type="button" id="button"  value=" 点击 ">
    <script type="text/javascript">
    document.getElementById('button').onclick=function(){
      location.href='http://'+location.host+'/caxh/down_execgyload?                page=1&jgm='+choice1+'&sh='+choice2;
    }
    </script>至于根据参数值改变而刷新,具体还要看参数值是怎么变的~
    我试了你的方法,提示是这样的:  TypeError: document.getElementById(...) is null
      

  14.   

    试一下吧:<input type="button" id="button"  value=" 点击 ">
    <script type="text/javascript">
    document.getElementById('button').onclick=function(){
      location.href='http://'+location.host+'/caxh/down_execgyload?                page=1&jgm='+choice1+'&sh='+choice2;
    }
    </script>至于根据参数值改变而刷新,具体还要看参数值是怎么变的~
    我试了你的方法,提示是这样的:  TypeError: document.getElementById(...) is null
    如果是按照代码来,是不会出现这个错误的,贴下你的代码看看吧。