使用javascript函数更新ASP.Net中的样式

使用javascript函数更新ASP.Net中的样式,asp.net,css,silverlight-4.0,styles,Asp.net,Css,Silverlight 4.0,Styles,好的,我有一个Silverlight 4应用程序,它位于一个带有几个横幅的页面上。根据Silverlight应用程序中的一些变量,我需要显示其中一个横幅,并重新定位Silverlight应用程序,使其与横幅底部对齐。为了实现这一点,我一直在使用HtmlPage.Window.Invoke(“MethodToShowTheBannerIWant”)。每个横幅都有自己的功能,可以尝试显示正确的横幅并定位应用程序以正确排列。差不多 function ShowFirstBanner() {

好的,我有一个Silverlight 4应用程序,它位于一个带有几个横幅的页面上。根据Silverlight应用程序中的一些变量,我需要显示其中一个横幅,并重新定位Silverlight应用程序,使其与横幅底部对齐。为了实现这一点,我一直在使用HtmlPage.Window.Invoke(“MethodToShowTheBannerIWant”)。每个横幅都有自己的功能,可以尝试显示正确的横幅并定位应用程序以正确排列。差不多

  function ShowFirstBanner() {
        FirstBannerStyle.style.display = 'block';
        SilverlightAppStyle.style.marginTop = '120px';
        SilverlightAppStyle.style.height = '495px';
    }
每个横幅看起来像

   <table id="FirstBannerStyle"  style="position:absolute;top:0px;left:0px;display:none;height:50px;" width=100% border="0" cellpadding="0">
<tr> 
  <td><img src="http://www.bannerimageurl.jpg" usemap="#Map2" border="0"></td> </table>

有一张这样的地图

  <map name="Map2"><area shape="poly" coords="763,19,769,91,985,92,981,69" href="http://www.xxxxxxx.com/cal.htm" target="_self" />
         <area shape="rect" coords="11,73,88,89" href="http://www.xxxxxxx.com/index.htm" target="_self">
         <area shape="rect" coords="121,70,186,88" href="http://www.xxxxxxx.com/courses.htm" target="_self">
         <area shape="rect" coords="217,70,327,90" href="http://www.xxxxxxx.com/ts.htm">
         <area shape="rect" coords="365,70,521,91" href="http://www.xxxxxxx.com/po.htm">
         <area shape="rect" coords="556,71,618,91" href="http://www.xxxxxxxx.com/au.htm" target="_self">
         <area shape="rect" coords="655,72,726,91" href="http://www.xxxxxxx.com/CU/index.htm" target="_self">
      </map>
  <form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost" style="height:100%;text-align:center">
    <object data="data:application/x-silverlight-2,"  type="application/x-silverlight-2" width="100%" height="100%">
      <param name="source" value="ClientBin/XXX.XXX.XXX.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50826.0" />
      <param name="autoUpgrade" value="true" />
      <param name="InitParams" value=<%=System.Configuration.ConfigurationManager.AppSettings.GetValues(0).FirstOrDefault()%>/>
      <param name="windowless" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

 <div id="InvisibleFrame"></div>    
</form>        

我遇到的问题是,这个过程在IE8中非常有效,但在IE9或Firefox中根本不起作用。当我的代码点击HtmlPage.Window.Invoke(“ShowFirstBanner”)时,它就卡在那里,永远不会超过那一行,但不会显示任何错误消息,而是会无限期地等待命令完成。如果我用函数注释掉代码,它将进行调用并正常继续。因此,我更新Firefox和IE9不喜欢的风格。有人有办法在所有浏览器中都能使用吗?

JavaScript中定义的“FirstBannerStyle”和“SilverlightAppStyle”在哪里

您需要通过其ID获取元素:

document.getElementById('FirstBannerStyle').style.display = 'block';
或者,如果您正在使用jQuery:

$('FirstBannerStyle').show()

它们不是,我只是用它们作为元素的id。我应该改用name属性吗?编辑:只是尝试使用name属性而不是id,没有任何区别。我还尝试过使用实际的javascript/css样式,效果也一样。