Javascript单击未按预期工作
我正在尝试实现下面所示的东西;单击看起来像按钮的div时,它将显示有关它们的详细信息。我使用的是内联Javascript以及外部Javascript文件。我的问题是,当我单击第一个div时,它会显示关于它的详细信息。但当我点击其他div时,什么也没发生 我的HTML代码是:Javascript单击未按预期工作,javascript,html,Javascript,Html,我正在尝试实现下面所示的东西;单击看起来像按钮的div时,它将显示有关它们的详细信息。我使用的是内联Javascript以及外部Javascript文件。我的问题是,当我单击第一个div时,它会显示关于它的详细信息。但当我点击其他div时,什么也没发生 我的HTML代码是: <html> <head> <title>Crash Test</title> <link href="css/style.css" type="text/css
<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>
碰撞试验
手机
var secArray=新数组();
secArray=[“华硕”、“宏达”、“苹果”、“三星”、“诺基亚”];
对于(var secCnt=1;secCnt,问题在于您未关闭详细信息div元素。更正代码:
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></div>');
} else {
document.write('<div id="viewSection' + secCnt + '" style="display:none;">You are viewing all about <b>' + secArray[secCnt - 1] + '</b> mobile phone: <br><br></div>');
}
}
for(var secCnt=1;secCnt你能提供你的问题吗?'dfsq'谢谢你百万次。你救了我免于发疯。我是多么愚蠢,我没有注意到未关闭的div。你太棒了!!!:)没问题,很高兴它有帮助!
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></div>');
} else {
document.write('<div id="viewSection' + secCnt + '" style="display:none;">You are viewing all about <b>' + secArray[secCnt - 1] + '</b> mobile phone: <br><br></div>');
}
}