2015-09-07 24 views
1

加載頁面時,圖像假設隱藏,直到url參數驗證並根據參數值顯示正確的圖像。這裏的問題是,圖像並沒有特別隱藏在快照代碼中,但是當相同的代碼在不同的項目中使用時,它就可以工作。這裏有什麼魔力!未在加載時間隱藏的圖像

腳本

 $(function() { 
     $('#graphic img').hide(); 
     $.ajax({ 
      url: 'ServerData.aspx', 
      dataType: 'text', 
      type: "GET", 
      success: function (data) { 
       var result = $.trim(data); 
       if (result == 2) { 
        $("#gate2").show(); 

       } else if (result == 3) { 
        $("#gate2").show(); 

       } else if (result == 4) { 
        $("#gate3").show(); 
       } else { 

       } 
      } 
     }); 
    }); 

事業部

<div class="portlet light bg-inverse"> 
    <div class="portlet-title"> 
     <div class="caption font-green-haze bold uppercase">Data</div> 
    </div> 
    <div class="portlet-body" style="overflow: auto;"> 
     <div id="divGraphic" style="text-align: center; margin: auto; width: 960px; height: 520px; overflow: hidden; position: relative;"> 
      <img src="Img/wg-platform.png" style="margin: auto; height: 691px;" /> 
      <%--<img src="img/wg-platform.png" style="margin: auto; margin-top: -210px;" />--%> 
      <div id="river"> 
       <div id="divRiver4"> 
        <img class="wg-river ease" src="img/wg-river.png" style="left: 264px; top: 330px; height: 143px; width: 359px;" /> 
        <img class="wg-river" style="left: 314px; top: 305px; right: 285px; height: 143px;" src="img/wg-river.png" /> 
        <img class="wg-river" style="left: 288px; top: 318px; right: 311px; height: 143px;" src="img/wg-river.png" /> 
       </div> 
      </div> 
      <div id="gate"> 
       <div id="divGate1"> 
        &nbsp;&nbsp;&nbsp; 
        <label class="lblGate">1</label> 
       </div> 
       <div id="graphic"> 
        <img id="gate1" src="img/Fully Close Red.png" style="left: 321px; top: 294px; z-index: 35; width: 154px; height: 92px; " /> 
        <img id="gate2" src="img/Fully Open Green.png" style="left: 333px; top: 300px; z-index: 35; width: 154px; height: 92px; " /> 
        <img id="gate3" src="img/Half Open Green.png" style="left: 316px; top: 299px; z-index: 35; width: 154px; height: 92px; " /> 
        <img id="gate4" src="img/Half Open Red.png" style="left: 317px; top: 296px; z-index: 35; width: 154px; height: 92px; " /> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
+0

您是否在您的代碼中導入了jQuery? –

+0

嘗試更改$('#graphic img')。hide();到$('#graphic')。hide();. – sinclair

+0

你如何包括jQuery - 異步或同步,如果同步,你包括它之前或之後的圖像? –

回答

2

刪除此

$('#graphic img').hide(); 

這些變化對

<img id="gate1" src="img/Fully Close Red.png" style="display:none; left: 321px; top: 294px; z-index: 35; width: 154px; height: 92px; " /> 
<img id="gate2" src="img/Fully Open Green.png" style="display:none; left: 333px; top: 300px; z-index: 35; width: 154px; height: 92px; " />  
<img id="gate3" src="img/Half Open Green.png" style="display:none; left: 316px; top: 299px; z-index: 35; width: 154px; height: 92px; " /> 
<img id="gate4" src="img/Half Open Red.png" style="display:none; left: 317px; top: 296px; z-index: 35; width: 154px; height: 92px; " /> 

確保在呈現圖片時隱藏圖片