两个函数(一个用php)是否可以用“;onclick”;

Are two functions (one with php) possible with "onclick"?

本文关键字:onclick 是否 函数 一个 php 两个      更新时间:2023-09-26

我有下面的脚本,它将同时激发两个函数。一个函数应调用/加载php文件(index.php以查询mysql),另一个函数则应运行javascript。这可能吗?感谢您提前提供的帮助。

$.get("index.php", {id : searchform, name : tweetfinder}, function() {
// Here you can do the other operations
onclick("submit");
$('searchform').submit();
});
</script>
<form id="searchform" name="tweetfinder">
<div class="input-append">
<input class="span3" autofocus="autofocus">
<button class="btn btn-primary">Do Stuff!</button>
</div></form>

这种方法(输入mysql查询作为函数?):

function showstuff(){
<?php
$get = mysql_query("SELECT * FROM `xxx` WHERE `xxx` = '$xxx' ORDER BY `rank` DESC")or die(mysql_error());
while($ass = mysql_fetch_assoc($get)){
$viewer = $ass['playername'];
echo "<a href='"index.php?viewuser=".$viewer."'">".$viewer."</a> , ";
};

如果你愿意使用AJAX(jQuery),那么我建议你。您所做的是,使用AJAX调用获取另一个文件的数据,并在其回调处执行其他操作。

$.get("index.php", {id : 5, name : MyName}, function() {
  // Here you can do the other operations
  alert('Do more things');
  $('formID').submit();
});

有关更多详细信息,请参阅此处