-1

我正在尝试使用 php 和 javascript 生成一些按钮来隐藏表单上的文本字段,但是每次按下按钮时它都会刷新页面。我不知道是按钮还是功能有问题,但我假设程序正在刷新,因为它出错了。

php生成的按钮

echo("<button id=\"button".$count."\" onclick=deleteAnswer(answer".$count."); return            false;>delete answer</button>");

javascript生成函数

write.innerHTML = write.innerHTML + "<button id=\"button"+answers+"\" onclick=\"deleteAnswer(\"answer"+answers+"\")\"; return false;>delete answer</button>";

实际的javascript函数

<script type="text/javascript">
function deleteAnswer(button)
{
    document.getElementById(button).style.visibility="hidden";
}
</script>
4

1 回答 1

0

你有几个问题answer".$count.""answer"+answers+"\"必须用 qoutes 和

echo("<button id=\"button".$count."\" onclick=deleteAnswer('answer".$count."'); return            false;>delete answer</button>");


write.innerHTML = write.innerHTML + "<button id=\"button"+answers+"\" onclick=\"deleteAnswer(\"answer"+answers+"\"); return false;">delete answer</button>"

 document.getElementById(button).style.visibility="hidden";

必须

 document.getElementById(button).style.display="hidden";

或者

 document.getElementById(button).style.visibility="visible";
于 2012-07-11T18:12:07.267 回答