用button隱藏和顯示 怎么實現(xiàn)不了 請指教
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style樣式</title>
</head>
<body>
? <h2 id="con">I love JavaScript</H2>
? <p> JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>
? <script type="text/javascript">
? var mychar=document.getElementById("con");
? mychar.style.color="red";
? mychar.style.backgroundColor="#CCC";
??
? function yin(){
? ? ? mychar.style.display="none";
? }
??
? ? ? function xianshi(){
? ? ? ? ??
? ? ? ?mychar.style.display="block";
? ?}
? ?
? </script>
? <form>
? <input type="button" name="xianshi" value="xianshi" onclick="xianshi()"/>
? <input type="button" name="yin" value="yin" onclick="yin()"/>
?</form>
?
</body>
</html>
2018-08-18
問題出在form表單,把form去掉就行
2018-11-29
看我代碼哈:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style樣式</title>
</head>
<body>
? <h2 id="con">I love JavaScript</h2>
? <p> JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>
? <script type="text/javascript">
? ?
? ?var conValue = document.getElementById("con");
? ?
? ?function setColor() {
? ? ? ?conValue.style.color = "red";
? ? ? ?conValue.style.backgroundColor.color = "#CCC";
? ?}
? ?
? ?function styleHide() {
? ? ? ?conValue.style.display = "none";
? ?}
? ?
? ?function showValue() {
? ? ? ?conValue.style.display = "block";
? ?}
?
? </script>
??
? <form>?
? ? <input type="button" value="改變顏色" onclick="setColor()" />
? ? <input type="button" value="點(diǎn)擊隱藏" onclick="styleHide()" />
? ? <input type="button" value="點(diǎn)擊顯示" onclick="showValue()">
? </form>
??
</body>
</html>
2018-10-17
你這個Id"con"沒有寫在input 里面啊