<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>display</title><script type="text/javascript">function hidetext(){var mychar=document.getElementById("con").style.display="none";}function showtext(){? var mychar=document.getElementById("con")? mychar=style.display="block";}</script></head><body><p id="con">這是我的第一個(gè)dom練習(xí)代碼</p><form><input type="button" onclick="hidetext" value="不顯示段落內(nèi)容" /><input type="button" onclick="showtext" value="顯示內(nèi)容" /></form></body></html>為什么不能隱藏和顯示啊? ?問題出在哪里?
3 回答

寒江北去
TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超2個(gè)贊
<input type="button" onclick="hidetext" value="不顯示段落內(nèi)容" />
<input type="button" onclick="showtext" value="顯示內(nèi)容" />
改正后應(yīng)該是
<input type="button" onclick="hidetext()" value="不顯示段落內(nèi)容" />
<input type="button" onclick="showtext()" value="顯示內(nèi)容" />
onclick后邊引號(hào)里寫的是函數(shù)的名字,既然是函數(shù),那么()就是不可少的
添加回答
舉報(bào)
0/150
提交
取消