나는 아래 그림 어떤 식으로 뭔가를 구현하기 위해 노력하고 원하는대로 작동하지 않는; 버튼처럼 보이는 div가 클릭되면 세부 정보가 표시됩니다. 인라인 자바 스크립트뿐만 아니라 외부 JavaScript 파일을 사용하고 있습니다. 내 문제는 첫 번째 div를 클릭하면 세부 정보가 표시된다는 것입니다. 하지만 다른 div를 클릭해도 아무 일도 일어나지 않습니다.자바 스크립트 클릭
<html>
<head>
<title>Crash Test</title>
<link href="css/style.css" type="text/css" rel="stylesheet">
<script src="javascript/functions.js" type="text/javascript"></script>
</head>
<body>
<fieldset>
<legend>Mobile Phones</legend>
<table width="100%">
<tbody>
<tr>
<td>
<script language="javascript">
var secArray = new Array();
secArray = ["Asus","HTC","Apple","Samsung","Nokia"];
for(var secCnt=1;secCnt<=secArray.length;secCnt++){
document.write('<div class="allSections currentSectionSelected" id="s">');
document.write('<div href="javascript:void(0);" class="tooltip tooltipSelected">');
document.write('<div style="text-overflow:ellipsis;width:92%;overflow:hidden;white-space:nowrap; padding:5px;font-weight: bold;" onclick="javascript:setSecName('+secCnt+',secArray);">');
document.write(secArray[secCnt-1]);
document.write('</div>');
document.write('</div>');
document.write('</div>');
}
</script>
</td>
</tr>
<tr>
<td>
<script type="text/javascript">
for(var secCnt=1;secCnt<=secArray.length;secCnt++){
if(secCnt == CurrentSection){
document.write('<div id="viewSection'+secCnt+'" style="display:block">You are viewing all about <b>'+secArray[secCnt-1]+'</b> mobile phone: <br><br>');
}
else{
document.write('<div id="viewSection'+secCnt+'" style="display:none;">You are viewing all about <b>'+secArray[secCnt-1]+'</b> mobile phone: <br><br>');
}
}
</script>
</td>
</tr>
</tbody>
</table>
</fieldset>
</body>
</html>
그리고 내 외부 자바 스크립트 파일의 코드는 다음과 같습니다 :
내 HTML 코드는
var CurrentSection =1;
function setSecName(sectioncount,sa){
CurrentSection=sectioncount;
load_details(sa);
}
function load_details(sa){
var secArray =sa;
for(var secCnt=1;secCnt<=secArray.length;secCnt++){
if(secCnt == CurrentSection){
document.getElementById('viewSection'+secCnt).style.display = "block";
}else{
document.getElementById('viewSection'+secCnt).style.display = "none";
}
}
}
내가 자바 스크립트 only.Please가 나를 도울 사용하여 위의 기능을 수행하고자합니다. 미리 감사드립니다.
문제의 수수께끼를 제공 할 수 있습니까? –