JavaScript函數下面是我在一個名爲testOne.php
從PHP調用函數
<html>
<head>
<script type="text/javascript">
function testAlert(firstValue, secondValue)
{
alert ("Passed: "+firstValue+secondValue);
}
</script>
</head>
<body>
....
</body>
</html>
<?php
function testPassedValues($One, $Two)
{
echo "<input type = \"button\" onclick = \"testAlert($One[2], $Two[2])\">Click Here!</input>";
}
$link = mysql_connect("localhost", "root", "");
if (mysql_select_db("myDatabase", $link))
{
$result = mysql_query("SELECT * FROM MYTABLE");
while($currRowOne = mysql_fetch_row($result) &&
$currRowTwo = mysql_fetch_row($result))
{
testPassedValues($currRowOne, $currRowTwo);
}
}
?>
爲了幫助理解,我打電話從PHP函數testPassedValues()
JavaScript方法testAlert()
一個PHP文件的代碼。但是,由於通話不成功,我不確定問題是什麼。在Mozilla(Firebug)中,我沒有發現任何問題,並且在Chrome-> Developer Tools中,控制檯中出現錯誤Uncaught Syntaxerror: Unexpected token ILLEGAL
。
任何人都可以請幫助我在這裏的根本原因?
謝謝你的建議,現在似乎已經解決了以前的問題。但是我得到一個新的錯誤信息'未捕獲的ReferenceError:testAlert未定義'。有關此錯誤的任何建議? – 2011-04-06 23:15:52
那麼你錯過了上面例子中的關閉標籤,可能是導致這個問題。雖然錯誤描述了這個問題 - 單擊按鈕時,函數testAlert不存在。 – Hamish 2011-04-06 23:18:00
那是我的錯。我輸入了上面的代碼,並忘記結束它。然而,實際的代碼有結尾標籤,我仍然得到相同的問題 – 2011-04-06 23:22:17