dongshixingga7900 2012-06-02 05:23
浏览 42
已采纳

将URL字符串传递给Javascript函数

I need to pass a URL to a JavaScript function something like the following.

<script type="text/javascript" language="javascript">

var xmlhttp='';   
function ajax()
{
    if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
         xmlhttp = new ActivexObject("Microsoft.XMLHTTP");
    }
}     

function someFunction(orders_per_page, url)
{
     ajax();
     var val=document.getElementById("txt_order_amount").value; 
     xmlhttp.onreadystatechange=function()
     {
          if(xmlhttp.readyState==4 && xmlhttp.status==200)
          {                
               document.getElementById("list").innerHTML=xmlhttp.responseText;
          }
     }

     xmlhttp.open("GET",url, true);
     xmlhttp.send();        
}
</script>

<select 
    id="cmb_page" name="cmb_page" 
    onchange="someFunction(this.value, "reports/OrderAmount.php?val="+val+"&orders_per_page="+orders_per_page+"&pageNo="+getSelectedPage();">

    <option value="1">Some Value</option>
</select>

I need to pass a URL string as mentioned on the onchange even of the <select><option></option></select> element. Is it possible?

  • 写回答

2条回答 默认 最新

  • duanaigua4033 2012-06-02 05:32
    关注

    try this

    onchange="someFunction(this.value, 'reports/OrderAmount.php?val='+val+'&orders_per_page='+orders_per_page+'&pageNo='+getSelectedPage());"
    

    Note: I have replaced double quotes with single quotes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示