从Comboc中选择项目后保持定位 我有一个带有2个组合框的窗体:StuttBox和CyryBox,StuttBox在我的页面的顶部,但是CyryBox在中间。我的问题是当我从中间的CyryBox中选择一个项目时,页面被刷新并返回到顶部。 那么如何保持相同的定位。 这是我的密码: <form id = "formbox" name="form" method = "POST" action="parproj.php"> <select id="statutbox" name="statut" onChange= "this.form.submit()" style= "width:300px;padding:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow: 0 3px 0;cursor:pointer;"> <?php $reponse2 = $bdd->query('select name from issue_statuses order by name asc;'); while ($donnees2 = $reponse2->fetch()) { $selected2 = (isset($_POST['statut']) and $_POST['statut'] == $donnees2["name"])?'selected="selected"':''; echo '<option value="'.$donnees2['name'].'" '.$selected2.'>'.$donnees2['name'].'</option>'; } $reponse2->closeCursor(); // Termine le traitement de la requête ?> </select> </form> <select id="categorybox" form="formbox" name="category" onChange= "this.form.submit()" style= "width:300px;padding:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow: 0 3px 0;cursor:pointer;"> <?php while ($donnees3 = $reponsecat->fetch()) { $selectedcat = (isset($_POST['category']) and $_POST['category'] == $donnees3["category"])?'selected="selected"':''; echo '<option value="'.$donnees3['category'].'" '.$selectedcat.'>'.$donnees3['category'].'</option>'; } $reponsecat->closeCursor(); // Termine le traitement de la requête ?> </select>

从Comboc中选择项目后保持定位 我有一个带有2个组合框的窗体:StuttBox和CyryBox,StuttBox在我的页面的顶部,但是CyryBox在中间。我的问题是当我从中间的CyryBox中选择一个项目时,页面被刷新并返回到顶部。 那么如何保持相同的定位。 这是我的密码: <form id = "formbox" name="form" method = "POST" action="parproj.php"> <select id="statutbox" name="statut" onChange= "this.form.submit()" style= "width:300px;padding:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow: 0 3px 0;cursor:pointer;"> <?php $reponse2 = $bdd->query('select name from issue_statuses order by name asc;'); while ($donnees2 = $reponse2->fetch()) { $selected2 = (isset($_POST['statut']) and $_POST['statut'] == $donnees2["name"])?'selected="selected"':''; echo '<option value="'.$donnees2['name'].'" '.$selected2.'>'.$donnees2['name'].'</option>'; } $reponse2->closeCursor(); // Termine le traitement de la requête ?> </select> </form> <select id="categorybox" form="formbox" name="category" onChange= "this.form.submit()" style= "width:300px;padding:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow: 0 3px 0;cursor:pointer;"> <?php while ($donnees3 = $reponsecat->fetch()) { $selectedcat = (isset($_POST['category']) and $_POST['category'] == $donnees3["category"])?'selected="selected"':''; echo '<option value="'.$donnees3['category'].'" '.$selectedcat.'>'.$donnees3['category'].'</option>'; } $reponsecat->closeCursor(); // Termine le traitement de la requête ?> </select>,php,html,Php,Html,有两种解决办法。检查下面的示例 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Scroll to an element</title> <script src="//code.jquery.com/jquery-1.9.1.min.js"></script> <style type="text/css"> #

有两种解决办法。检查下面的示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scroll to an element</title>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<style type="text/css">
    #category {margin-top:500px}
    #article {margin-top:250px}
</style>

</head>
<body>

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<select name="status" id="status" onchange="this.form.submit();">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>    
</select><br />
<select name="category" id="category" onchange="this.form.submit();">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
</select>
<input type="submit" name="button" value="button" />
</form>
<div id="article">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

<?php
    if(isset($_POST["status"]) && $_POST["status"] != 0){

        // 1st solution 
        header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] . "#category");

        // or

        // 2nd solution
        echo '<script type="text/javascript">$("html, body").animate({scrollTop: $("#category").offset().top}, "slow");</script>';
    }
?>
</body>
</html>

不要忘了对你不会使用的解决方案进行注释。this.form.submit是可选的,您可以通过常规的提交按钮提交表单

您的第二个选择超出了表单标记。它适用于两个组合框,但我希望仅当我从categorybox@Salma我为你写了一个完整的例子,所以我希望你会觉得它有帮助。试一试:非常感谢,我两个都试过了,我一直被带到页面顶部,我不想使用提交按钮:@Salma那么,既然这还不太清楚,你是否解决了你的问题?还没有,我试过你的解决方案,但没有效果,我看不出问题出在哪里: