使用下拉列表显示网页

时间:2014-04-09 05:41:22

标签: jquery drop-down-menu

我有一个下拉列表,如

<h1>IMy Search Engine</h1>
<form id="formid">
<select name="days" id="selectid" onchange="check()">
    <option value="">choose</option>
    <option value="thirty.php">Last 30 days</option>
    <option value="sixty.php">Last 60 days</option>
    <option value="ninety.php">Last 90 days</option>
    <option value="calender.php">custom</option>
</select>
</form>

每个选项在下一个窗口中显示另一个网页。我想使用show()hide()jqueries在同一窗口中显示另一个网页。有人帮忙吗?

3 个答案:

答案 0 :(得分:0)

这样做:

document.getElementById('selectid').onchange=function(){
   if(this.value){
     window.location=this.value; 
   }
};

答案 1 :(得分:0)

有几种方法可以做到这一点:

  

1)选项

使用iframe并更新其src =&#34;动态网址&#34;改变选择。

  

2)选项

使用jquery ajax to get dynamic contents and set as html in the div或任何你想要的html元素。

答案 2 :(得分:0)

    // In your current page append following code
    // this section hold your new page value
   <pre>

   </pre>

   // In jquery
   <script>

     $(document).ready(function(){

        //change event of dropdown

         $('#selectid').on('change',function(){

              $this = $(this);
              if( $this.val().length )
              {
                  // ajax call to get file contents
                  $.ajax({
                     url    :  "getFile.php",
                     type   :  "POST",
                     data   :  {'page':$this.val()},
                     success:  function(n)
                     {
                         $('pre').html(n);
                     }
                 });
              }
         });
      });   
   </script>

   // requested page(ex.sixty.php) and getFile.php should be in same directory
   // getFile.php 
    <?php
 if( isset($_POST['page']) )
 {
    echo file_get_contents($_POST['page']);
 }
    ?>