“Silverlight”中擷取“HTML元素和參數”及JS互動

來源:互聯網
上載者:User
1、擷取HTTP串連中的參數
http://localhost:5526/sl.aspx?user=root&password=root

HtmlPage.Document.QueryString
取到的是一個字典IDictionary<string, string>
key=user,value=root
key=password,value=root

2、從“<param name="initparams" value="ChartType=WaterMonitoring" />”中擷取“initparams”參數

  e.InitParams["ChartType"].ToString();

3、“HTML:<input type="hidden" name="hf_qty" id="hf_qty" value="705.5" />”中擷取“input元素”

  HtmlDocument doc = HtmlPage.Document;
  HtmlElement el = doc.GetElementById("hf_qty");
  var value = el.GetProperty("value");

4、“與JavaScript互動擷取”
  首先在HTML頁面寫一個JavaScript:

  <script type="text/javascript">
  function GetValue() {
  return document.getElementById("hf_qty").value;
  }
  </script>

  在Silverlight代碼裡:

  var value = HtmlPage.Window.Invoke("GetValue");

5、“Silverlight”中操作“HTML”元素
  HTML:
  <div id="myDIV" style="background:blue;width:20%;height:20%">  
  <asp:Silverlight ID="Xaml1" runat="server"   
  Source="~/ClientBin/SilverlightApplication27.xap" MinimumVersion="2.0.30930.0"   
  Width="50%" Height="100%" />  
  </div>

  Silverlight:
  private void Button_Click(object sender, RoutedEventArgs e)
  {
  HtmlDocument doc = HtmlPage.Document;
  HtmlElement div = doc.GetElementById("myDIV");
  div.SetStyleAttribute("background", "green");

  }

  幫忙投一票唄 

   

  參考部落格:Silverlight和JS互動 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.