0

如何在页面加载时点击某个按钮?

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>
$("#submit").click(function() {
  $("#submit").click();
});
</script>

</head>

<body>

<form action="Untitled-9.php" method="post">
<input type="text" name="name" value="dsa"/>
<input type="submit" name="submit" value="Register" />
</form>


<?php

$name = $_POST['name'];

echo $name;

?>


</body>

这是我拥有的代码,我希望在加载页面时自动按下“注册”按钮

4

5 回答 5

4
<?php if ($_POST["name"] == "") { ?>

<script type="text/javascript">
    $(document).ready(function() {
        $("input[name=submit]").click();
    });
</script>

<?php } else {

    echo $_POST["name"];

} ?>
于 2012-11-27T22:47:27.107 回答
2

试试这个:$("#submit").trigger('click');

于 2012-11-27T22:47:52.460 回答
1
<script>
    $(document).ready(function() {
      $("#submit").click();
  });
</script>

并将 id 放在:

<input type="submit" name="submit" value="Register" id="submit/>
于 2012-11-27T22:47:50.960 回答
0
<script type="text/javascript">
  $(function(){
     $("#submit").trigger('click');
  });
</script>

会像其他人建议的那样工作

你也可以使用

<script type="text/javascript">
  $(function(){
     $("form").submit();
  });
</script>
于 2012-11-27T22:55:14.550 回答
0

<script>
function aclick(){
document.getElementById("submit").click();	
}
</script>
<body onLoad="aclick();">
<form action="name.php" method="post" >
<p >
<label>Email</label><br />
<input type="text" name="number" value="<?php echo $row['Mobileno']; ?>" /><br />
<label>Message</label><br />
<textarea name="msg">  </textarea><br /></p>

<input type="submit" name="submit" value="For Old Student Next to Reciepent" style="background-color:#006; color:#FFF;" id="submit" />
</form>





</body>

于 2018-06-22T04:37:19.497 回答