Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript显示/隐藏元素,为什么不';这个代码不起作用吗?_Javascript_Html_Onclick_Show Hide - Fatal编程技术网

Javascript显示/隐藏元素,为什么不';这个代码不起作用吗?

Javascript显示/隐藏元素,为什么不';这个代码不起作用吗?,javascript,html,onclick,show-hide,Javascript,Html,Onclick,Show Hide,因此,正如您所看到的,我使用了有趣的javascript来显示/隐藏元素,但是当您单击.png时,它会显示文本,但不会隐藏其他元素的文本。我一直在一遍又一遍地浏览这个脚本,谷歌搜索它,我想不出答案。我想我需要另一双眼睛,所以如果有人看到这个,让我知道是否有错误或者我是否丢失了一些代码 <html> <head> <meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no" /&

因此,正如您所看到的,我使用了有趣的javascript来显示/隐藏元素,但是当您单击.png时,它会显示文本,但不会隐藏其他元素的文本。我一直在一遍又一遍地浏览这个脚本,谷歌搜索它,我想不出答案。我想我需要另一双眼睛,所以如果有人看到这个,让我知道是否有错误或者我是否丢失了一些代码

<html>
<head>
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="NKit.js"></script>

<link rel="stylesheet" type="text/css" href="style.css" />

<script type="text/javascript">

function showStuff(id) {
    document.getElementById(id).style.display = 'block';
}
function hideStuff(id) {
    document.getElementById(id).style.display = 'none';
}

</script>

</head> 

<body> 

<div class="content">

<section class="left">  

        <p>
            <a href="#" onclick="showStuff('character1');" onclick="hideStuff('character2');"><img src="character1.png" id="char1" /></a>

        </p> 

        <p>
            <a href="#" onclick="showStuff('character2');" onclick="hideStuff('character1');"><img src="character2.png" id="char2" /></a>
        </p> 

</section>

<section class="right">

        <span id="character1" style="display: none;">Show character1 information</span> 

        <span id="character2" style="display: none;">Character 2 information</span> 

</section>

</div>

</body> 
</html>

函数showStuff(id){
document.getElementById(id).style.display='block';
}
函数hideStuff(id){
document.getElementById(id).style.display='none';
}

显示字符1信息 字符2信息
为什么每个锚点都有两次“onClick”?为什么每个锚点都有两次“onClick”?
<a href="#" onclick="showStuff('character1');" onclick="hideStuff('character2');">
onclick="function() { showStuff('character1'); hideStuff('character2'); }