代码之家  ›  专栏  ›  技术社区  ›  Webshop2229

Javascript语言位置.href不重定向

  •  0
  • Webshop2229  · 技术社区  · 6 年前

    我的问题是 location.href 不会将我重定向到我想要的页面。它做什么,页面只是重新加载。

    preventdefault() ,但仍然存在同样的问题。

    <script type="text/javascript">
        $(document).ready(function(e) 
        {
            $('#submitButton').click(function(e)
            {
                e.preventDefault();
                var iro = $('#iro').val();
                var date_start = $('#date_start').val();
                var date_end = $('#date_end').val();
                location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
            });
        });
    </script>
    
    <select name="iro" id="iro" class="input input-select">
        <?php
        $ertek = isset($_POST["iro"]) ? $_POST["iro"] : '' ;
        $get_irok = mysqli_query($kapcs, "SELECT iro_id, iro_nev FROM iro WHERE iro_status = 1 ORDER BY iro_nev ASC");
        if(mysqli_num_rows($get_irok) > 0 )
        {
            while($irok = mysqli_fetch_assoc($get_irok))
            {
                $selected = $ertek == $irok['iro_id'] ? ' selected="selected"':'';
                echo '<option ' . $selected . ' value="'.$irok['iro_id'].'">'.$irok['iro_nev'].'</option>';
            }
        } 
        ?>
    </select>
    
    <td style="text-align: center;">
    <input autocomplete="off" class="datepicker" type="text" name="date_start" id="date_start" required value="<?php if(isset($_POST['date_start'])) { echo $_POST['date_start'];} ?>" />
    </td>
    <td style="text-align: center;">
    <input autocomplete="off" class="datepicker" type="text" name="date_end" id="date_end" required value="<?php if(isset($_POST['date_end'])) { echo $_POST['date_end'];} ?>" />
    </td>
    <td style="text-align: center;"><button class="btn saveButton" name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   Antony Vibin    6 年前

    尝试位置.替换

    location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');
    
        2
  •  -2
  •   Negi Rox    6 年前

    更改此行

     <td style="text-align: center;"><button class="btn saveButton" name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>
    

    为了这个

     <td style="text-align: center;"><input class="btn saveButton" name="submitButton" id="submitButton" type="button">Lekérdezés</button></td>
    
     $('#submitButton').click(function(e)
            {
                var iro = $('#iro').val();
                var date_start = $('#date_start').val();
                var date_end = $('#date_end').val();
                location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
            });