“Silverlight”中获取“HTML元素和参数”及JS交互
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");
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步