【发布时间】:2013-12-16 10:46:36
【问题描述】:
我有这个 HTML 代码:
<div id="texttheory" class="centertext">'. $short .' </div>';
<button id="thbutton" class="theory_button" onclick="javascript:changetheory('.$long.')">
<img id="imagebutton" src="./images/arrows.png" width="15px" heigth="22px">
</button>
我在一个由 javascript 函数调用的 php 脚本中生成:
function showTheory (kl) {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("theory").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gettheory.php?kl="+kl,true);
xmlhttp.send();
}
函数 changetheory 在 js 库中正确包含在 html 头标签中,它的工作原理如下:
function changetheory (content, old) {
document.getElementById("texttheory").innerHTML= content;
document.getElementById("thbutton").setAttribute ('onclick', "javascript:changetheory("+old+", "+content+")");
}
当我单击 thbutton 切换两个文本时,我得到错误: 未捕获的 SyntaxError:意外的标识符 在 html 文件的第 1 行。 任何人都可以看到问题是什么?
【问题讨论】:
标签: javascript php html ajax