【问题标题】:Append url with value of select option using php使用php附加带有选择选项值的url
【发布时间】:2014-02-21 11:11:15
【问题描述】:

我在 jquery mobile 中有一个选择菜单,我想在用户选择一个选项时显示另一个网站的表格,但是当用户选择不同的选项时表格需要更改。

我正在使用简单的 HTML dom 解析器,但我想知道如何将所选选项的值添加到 url,所以如果用户选择值为 32 的选项,它会将 32 添加到 url 以便PHP 代码中使用的 url 将是“http://www.generalconvention.org/gc/deputations?diocese_id=32”。如何使用 PHP 做到这一点?

<?php
        include('simple_html_dom.php');

        // get DOM from URL or file
        $html = file_get_html('http://www.generalconvention.org/gc/deputations?diocese_id=');
        // Find all tables 
        foreach($html->find('table') as $element) 
        echo $element;
?>

【问题讨论】:

    标签: php jquery html


    【解决方案1】:

    捕获值后,像这样连接它:

    <?php
    
            $value = "Your form value";
    
            include('simple_html_dom.php');
    
            // get DOM from URL or file
            $html = file_get_html('http://www.generalconvention.org/gc/deputations?diocese_id=' . $value);
            // Find all tables 
            foreach($html->find('table') as $element) 
            echo $element;
    ?>
    

    【讨论】:

    • 但这不是只适用于静态值吗?如何将 $value 设置为所选选项的值?
    【解决方案2】:

    你可以做ajax调用:

        $(".comboboxClass").change(function(){
            $("#divHtml").load('http://www.generalconvention.org/gc/deputations?diocese_id='+
    $(this).find('option:selected').val()+' table.deputies'
            );
        });
    

    #divhtml 中加载表.deputiesload 的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-24
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多