[英]javascript and css in asp.net
我正在使用c#將應用程序移動到asp.net中,其中已經有一些javascript。
我有以下javascript函數:
function toggle(id) {
var tog = document.getElementById(id);
if (tog == null) { return; }
var bExpand = tog.style.display == '';
tog.style.display = (bExpand ? 'none' : '');
}
我稱之為<a href="javascript:void(0);" onclick="toggle('programinfo');" class="nobold">[-]</a>
<a href="javascript:void(0);" onclick="toggle('programinfo');" class="nobold">[-]</a>
正如您所看到的,它唯一能做的就是將display屬性從none切換為空白,使id'programinfo'顯示或不顯示。
來自coldfusion它完美地工作,我只有一個名為programinfo的div,它會在每次點擊鏈接時顯示或不顯示div的內容。 但是,它現在沒有做任何事情。 如果我在值tog.style.display
上添加一個警告它會顯示一個空白值,或者值為none,所以我知道它正在獲取值,但它不再翻轉該值。
我在div和table上都嘗試過,沒什么。 然后我甚至嘗試添加一個style="display:none;"
默認情況下,為了使它消失而對表進行屬性,但即便如此仍然無法正常工作。
我在這一點上的唯一猜測是它與asp有關,但我無法在任何地方找到它,所以我不確定。 有沒有人有任何想法? 謝謝。
編輯 - 通過請求將html輸出發送到瀏覽器:
<table width="100%" border="0" class="dgbc" cellspacing="0" cellpadding="5">
<tr>
<td colspan="12" class="section_header" style="background-repeat:no-repeat;background-image:url(images/tms_side1.jpg);margin:0;background-position:right;">
<span style="float: right;"><a href="javascript:void(0);" onclick="toggle('programinfo');" class="nobold">[-]</a></span>
PROGRAM INFO
</td>
</tr>
<tr>
<td valign="top">
<table width="100%">
<div id="programinfo" style="display:none;">
blah blah blah
</div>
</table>
</td>
</tr>
</table>
我認為你遇到的問題是HTML標簽無效使用。
<table width="100%">
<tr>
<td>
<div id="programinfo" style="display: none;">
blah blah blah
</div>
</td>
</tr>
</table>
將Div標簽放在td和tr中。 您將解決問題。 這個問題在IE6和IE7中仍然存在。 希望這可以幫助。
如果您從"display:none"
,然后將顯示切換為空白,那么會顯示什么? CSS中有"display:block"
嗎? 您可以嘗試將顯示屏切換為'block'
而不是空白嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.