この記事では、マウスをクリックしてテーブルの行を展開または非表示にするJSの方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
コードコピーは次のとおりです。
<!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> JSはマウスクリックを実装してテーブルの行を展開/非表示にします</title>
</head>
<body>
<スクリプト言語= "javascript">
function testblack(tagname){
var obj = document.getElementById(tagname);
if(obj.style.display == ""){
obj.style.display = "none";
}それ以外{
obj.style.display = "";
}
}
</script>
<Table CellPacing = "0" CellPadding = "0">
<tr onclick = "testblack( 'divc');">
<td bgcolor = "#00ccff">私をクリック!</td>
</tr>
<tr id = "divc">
<td bgcolor = "#9966ff"> </td>
</tr>
</table>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。