我正試圖編寫單擊按鈕時寫入文件的代碼。我開始讓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
您的代碼有效,但您需要。 –