0

我对这里的一个问题感到震惊。在页面加载时,我想隐藏 div 面板。一旦用户选择了我想在 div 中显示获取的价格的值。

这是我的程序。

我对两个问题感到震惊

** I am unable to show the div once user selects an Option

I am unable to set the value inside the div.**

<html>
<head>
<title>Online Book Store</title>
<script>
function displayResult(selTag)
{
var x=selTag.options[selTag.selectedIndex].value;
mydiv = document.getElementById("panel");
mydiv.style.visibility = "block"; //to show it
document.getElementById("field_name").innerHTML = x;
}


function hideDiv()
{
    mydiv = document.getElementById("panel");
    mydiv.style.display = "none"; //to hide it  
}
</script>
</head>
<Body Bgcolor = "wheat" onload="hideDiv()">
<center>
<h2> welcome to online shopping</h2>
<form Action = "./onlinebookstore">
select Book
 <select name = "book" onchange="displayResult(this)">
 <option></option>
 <option value=  111>C programming language</option>
 <option value = 112>Java programming language</option>
 <option value = 112>Network analysis</option>
 <option value = 114>Advaced computer Networks</option> 
 <option value =115>Programming analysis</option>
 <option value = 116>Advanced data strctures</option>
 <option value = 117>Advanced java and web technologies</option>
 <option value = 118>Electronic devices</option>
 <option value = 119>Computer Graphics</option>
 <option value = 120>Microprocessors</option>
 <option value = 121>Oracle</option>
 </select>
 <br><br>
  quantity <Input type = "text" name = "Quantity">
 <br><br>
 
  <br><br>
 <div id="panel">
 Price <div id="field_name">TEXT GOES HERE</div>
</div>
 <br><br>
 
 <input type = "submit" name = "s" value = "ADDItem">
 <input type = "submit" name = "s" value = "Removeitem">
 <input type = "submit" name = "s" value = "showitems">
 <input type = "submit" value = "Logout" name = "s">
 </form>
</center>
</Body>
</html>

有人可以帮我吗

4

1 回答 1

3
  • 您正在混合和匹配可见性和隐藏性。

改变:

mydiv.style.visibility = "block"; // This value is invalid.

mydiv.style.display= "block";

如果元素通过调用隐藏display:none,可见性对其没有影响(即使可见性属性值是正确的)

  • 在元素之后调用正文的hide()inwindow.onload或 end。

  • 重新访问您的选项值,它们中有空格(至少在小提琴中)。

  • .value您可以使用即 selTag.value直接访问选择选择值

演示

于 2013-07-09T19:18:27.630 回答