How TO - Full Page Tabs
このサイトを見ながらコードを書いて、タブの切り替え機能を作成しています。
しかし文字を切り替えることができません。
エラーメッセージには、openiCityが未定義です と出ます
どこがおかしいのか見ていただけませんか?
bracketsとgooglechrome を使いました。
エラーメッセージ
Uncaught SyntaxError: Unexpected token ';'
Untitled-79.html:52 Uncaught ReferenceError: openCity is not defined
at HTMLButtonElement.onmouseover (Untitled-79.html:52)
onmouseover @ Untitled-79.html:52
Untitled-79.html:53 Uncaught ReferenceError: openCity is not defined
at HTMLButtonElement.onmouseover (Untitled-79.html:53)
該当のソースコード
JavaScript、html、css
html
1<html> 2<head> 3 <meta name="viewpoint" content="width=device-width,initial-scale=1"> 4 <style>*{box-sizing: border-box} 5 body{font-family: "Lato",sans-serif;} 6 .tab{ 7 float: left; 8 border: 1px solid #ccc; 9 background-color: #f1f1f1; 10 width:30px; 11 height: 300px; 12 } 13 .tab button{ 14 display: block; 15 background-color: inherit; 16 color: black; 17 padding: 22px 16px; 18 width: 100%; 19 border: none; 20 outline:none; 21 text-align: left; 22 cursor: pointer; 23 font-size: 17px; 24 } 25 .tab button:hover{ 26 background-color: #ddd; 27 } 28 .tab button.active{ 29 background-color:#ccc; 30 } 31 .tabcontent{ 32 float: left; 33 padding: 0px 12px; 34 border: 1px solid #CCC; 35 width: 70%; 36 border-left: none; 37 height: 300px; 38 display: none; 39 } 40 .clearfix::after{ 41 content: ""; 42 clear: both; 43 display: table; 44 } 45 </style> 46 </head> 47<body> 48 <h2>Hover Tabs</h2> 49 <p>Move the mouse over a button inside the tabbed menu;</p> 50 <div class="tab"> 51 <button class="tablinks" onmouseover="openCity(event,'London')">London</button> 52 <button class="tablinks" onmouseover="openCity(event,'Paris')">Paris</button> 53 <button class="tablinks" onmouseover="openCity(event,'Tokyo')">Tokyo</button> 54 </div> 55 56 57 <div id="London" class="tabcontent"> 58 <h3>London</h3> 59 <p>London is the capital city of England.</p> 60 </div> 61 <div id="Paris" class="tabcontent"> 62 <h3>Paris</h3> 63 <p>Paris is the capital city of France.</p> 64 </div> 65 <div id="Tokyo" class="tabcontent"> 66 <h3>Tokyo</h3> 67 <p>Tokyo is the capital city of Japan.</p></div> 68 <div class="clearfix"></div> 69 <script> 70 function openCity(evt,cityName){ 71 var i,tabcontent,tablinks;( 72 tabcontent=document.getElementsByClassName("tabcontent"); 73 for (i=0; i<tabcontent.length;i++){ 74 tabcontent[i].style.display="none"; 75 } 76 tablinks =document.getElementsByClassName("tablinks"); 77 for (i=0; i<tablinks.length; i++){ 78 tablinks[i].className=tablinks[i].className.replace("active",""); 79 } 80 document.getElementById(cityName).style.display="block"; 81 evt.currentTarget.className+="active"; 82 } 83 </script> 84 </body></html> 85 86
補足情報(FW/ツールのバージョンなど)
googlechromeを使ってエラーコードを出しました。
回答1件
あなたの回答
tips
プレビュー