我正试图编写单击按钮时写入文件的代码。我开始让JavaScript的(和jQuery)调用PHP文件实验:Javascript调用php?
<!DOCTYPE html>
<html>
<title>
Test Page
</title>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<button id="ST1U" onclick="feedback(this)">I understand</button>
<button id="ST1N" onclick="feedback(this)">I don't understand </button>
<script type="text/javascript">
function feedback(buttonElement){
var bcid= buttonElement.id;
if(bcid==='ST1U'){
$('#output').load('form.php');
}
else if(bcid==='ST1N'){
alert("We are sorry you didn't understand")
}}
</script>
,并在文件 'form.php的':
<script type-'text/javascript'>
alert('thank you for your responds')
</script>
然而,当我点击第一个按钮,php脚本似乎没有运行,因为我没有看到警报消息。任何想法,为什么它不工作?
我在代码中看不到“id =”输出。 – Sean
您的代码有效,但您需要。 –