大家帮我看看JS代码有什么问题?开始时div是隐藏的,点击按钮之后div显示,但是点击按钮后没反应!

<--
<button type="submit" name="judge" onclick="displaySelect();" value="judge">评分</button>

<div class="scoreNumberList" id="scoreList" style="display: none;">

<select>

<option onclick="optionScoreNumber(1)">1</option>

<option onclick="optionScoreNumber(2)">2</option>

<option onclick="optionScoreNumber(3)">3</option>

</select>

</div><!-- scoreNumberList结束 -->

<script type="text/javascript">

function displaySelect() {

var myId = document.getElementById("scoreList");

if(myId.style.display == "none"){

document.getElementById("scoreList").style.display = "block"; //当div是隐藏的时候,点击后会显示

}

else {

document.getElementById("scoreList").style.display = "none";//当div是显示的时候,点击后会隐藏

}

</script>
-->

<script type="text/javascript">

function displaySelect() {

var myId = document.getElementById("scoreList");

if(myId.style.display == "none"){
myId.style.display = "block"; //当div是隐藏的时候,点击后会显示
} else { 
myId.style.display = "none";//当div是显示的时候,点击后会隐藏
}
}



</script>
换成这段代码就行了  你少了个花括号,建议用谷歌浏览器控制台调试

追问

麻烦大哥再帮我看下这个函数,给您追加,我想点击下拉列表中的一个值后跳转并传值,但是点击之后并没有反应,谢谢大哥!
function optionScoreNumber(scoreNumber){
location.href = '../../../src/com/servlet/gongyuAdmin/DoJudgeScore?scoreNumber='+scoreNumber;
}

追答

这个方法不能直接加在option的标签上面 你得在select的值发生改变的时候去执行才行噢。

1

2

3

function displaySelect() {

var myId = document.getElementById("scoreList");

if(myId.style.display == "none"){
myId.style.display = "block"; //当div是隐藏的时候,点击后会显示
} else {
myId.style.display = "none";//当div是显示的时候,点击后会隐藏
}
}

function optionScoreNumber(scoreNumber){
location.href = '../../../src/com/servlet/gongyuAdmin/DoJudgeScore?scoreNumber='+scoreNumber;
}

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-06-09
目测 函数不完整 最后少了个}
相似回答