-1
在VS 2013中使用asp.net。錯誤使用javascript顯示div
我有以下代碼。
<div id="HPInformation">
<div>
<div id="HPInfoPopUp" style="display: none;">
<div id="HPInfoPopUpTitle">Information</div>
<div id="HPInfoPopUpInternalPanel">
<table id="HPInfoTable">
<tr>
<td>Contact</td>
<td>Harris Redknapp</td>
</tr>
<tr>
<td>Email</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Telephone</td>
<td>0800 888888</td>
</tr>
<tr>
<td>Address</td>
<td>1 Bali Court</td>
</tr>
<tr>
<td></td>
<td>Middlesbrough</td>
</tr>
<tr>
<td></td>
<td>TS21 5TT</td>
</tr>
</table>
</div>
</div>
</div>
<asp:Image ID="informationImg" ImageUrl="~/images/HomeInformation.gif" runat="server" />
<span>
<h3>INFORMATION</h3>
</span>
</div>
<script type="text/javascript">
var e = document.getElementById('HPInformation');
e.onmouseover = function() {
document.getElementById('HPInfoPopUp').style.display = 'block';
document.getElementById('informationImg').style.display = 'none';
}
e.onmouseout = function() {
document.getElementById('HPInfoPopUp').style.display = 'none';
document.getElementById('informationImg').style.display = 'block';
}
</script>
<script type="text/javascript">
var e = document.getElementById('HPContact');
e.onmouseover = function() {
document.getElementById('HPContactPopUp').style.display = 'block';
document.getElementById('contactImg').style.display = 'none';
}
e.onmouseout = function() {
document.getElementById('HPContactPopUp').style.display = 'none';
document.getElementById('contactImg').style.display = 'block';
}
</script>
<div id="HPContact">
<div>
<div id="HPContactPopUp" style="display: none;">
<div id="HPContactPopUpTitle">Information</div>
<div id="HPcontactPopUpInternalPanel">
<table id="HPcontactTable">
<tr>
<td>Contact</td>
<td>Harris Redknapp</td>
</tr>
<tr>
<td>Email</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Telephone</td>
<td>0800 888888</td>
</tr>
<tr>
<td>Address</td>
<td>1 Bali Court</td>
</tr>
<tr>
<td></td>
<td>Middlesbrough</td>
</tr>
<tr>
<td></td>
<td>TS21 5TT</td>
</tr>
</table>
</div>
</div>
</div>
這是因此,當在頁面上示出的特定的DIC HPInformation或HPContact被鼠標懸停在一個div。爲惠普信息的JavaScript工作正常,但惠普聯繫人不,我不明白爲什麼。誰能幫忙?
因爲'HPContact'是不是在你打電話'的document.getElementById( 'HPContact')時DOM'(了'div'與'id'是你的腳本之後)。你應該得到一個錯誤,如'不能設置屬性'onmouseover'null' –
所以如果我把它移到它應該工作之前 – Silentbob
那麼試試吧。其實,它應該工作。 –