如何将javascript onclick功能与php集成? [英] How can I integrate javascript onclick function with php?
问题描述
我的onclick功能与php集成有问题。有人可以帮忙
I am having a problem with onclick function integrating it with php .Can someone please help
以下是我的代码
<html>
<head>
<title></title>
<script language="Javascript">
function delete()
{
val del=confirm("Do you wanto delete the player?");
if(del==true)
{
alert("player Deleted");
}
else
{
alert("record not deleted");
}
return del;
}
</script>
</head>
<?php
Echo "
<a href='delete.php?player_id=$player_id' onclick='delete()'>Delete</a>"
?>
推荐答案
我找到了一个非常好的解决方案。但是,它为您的代码添加了一些额外的功能。我不建议太多使用这种方法。我是一个新的PHP开发人员,所以这个方法有可能也可以做不到的事情。
I found a pretty good solution. However, It adds a little extra to your code. I do not recommend using this method too much. I am a new PHP developer, so there are probably somethings this method can and cannot do.
我似乎无法阻止此方法加载新页面,因此最好的方法是将php添加到文件的开头。这也是使用AJAX(我的意见)
also I cannot seem to prevent this method from loading a new page, so the best way is to add your php to the beginning of the file. This is also a better solution for using AJAX (my opinion)
的更好解决方案,如果当前文件是index.php ...
if the current file is index.php...
制作表格标签元素
'<form action="index.php" method="post">'
'<input type="submit" name="helloWorld" value="hello World">'
'</form>'
这里您将显示您正在尝试的内容,只需点击一下
here you will display the content of what you are trying for, with a click
'<article>'
'<?php echo myFunction(); ?>'
'</article>'
这个下一个php标记可以去任何地方,只要它在同一个文件中......除非你知道如何解决。最好的地方是在HTML之前。
this next php markup can go anywhere as long as it it is in the same file... Unless you know how to work around. Best place is before the HTML.
'<?php '
'function myFunciton() {'
'if (isset($_POST[helloWorld])) {'
'echo "hello world"; ... your methods'
'}'
'}'
或者您可以在不使用功能的情况下直接访问它
or you could directly access it without using a function
<body>
<form action="index.php" method="post">
<input type="submit" name="hello" value="hello">
<input type="submit" name="goodBye" value="goodBye">
</form>
<article>
<?php
if (isset($_POST[hello])) {
echo "This happens if you click hello";
}
if (isset($_POST[goodBye])) {
echo "This happens if you click goodBye";
}
?>
</article>
</body>
这篇关于如何将javascript onclick功能与php集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!