从“Silverlight”,怎样获取这个HTML元素中的值?
从“Silverlight”,怎样获取这个HTML元素中的值?
HTML:
<input type="hidden" name="hf_qty" id="hf_qty" value="705.5" />
问题:“Silverlight”下怎样获取“input”元素的“value”值?“HtmlPage.Document.QueryString”可以么???
[解决办法]
可以使用 HtmlDocument doc = HtmlPage.Document;解决你的问题。
引用类库using System.Windows.Browser;
在按钮事件中调用访问,
private void Button_Click(object sender, RoutedEventArgs e){ HtmlDocument doc = HtmlPage.Document; HtmlElement div = doc.GetElementById("myDIV"); div.SetStyleAttribute("background", "green");}
[解决办法]
SL中也可以使用JS的。。
[解决办法]
<object id="SL" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="800px"> <param name="source" value="../ClientBin/XXX.xap" /> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="4.0.60310.0" /> <param name="autoUpgrade" value="true" /> <param name="windowless" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration: none"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style: none" /> </a></object><script type="text/javascript" language="javascript"> function getMess(str) { $.post("Default.aspx", { "action": "search", "param": str }, function (data) { if (data.toString().indexOf("Longin.aspx") > -1) { window.top.location.href = '../Longin/Longin.aspx'; } setTimeout(function () { var slHost = document.getElementById("SL"); var page = slHost.Content.Page; page.process(data); }, 1000); }); } </script>using AjaxPro; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["action"] != null) { if (Request["param"] != null) { System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); sb.Append(Request["param"].ToString()); string strs = jss.Serialize(sb.ToString()); Response.Write(sb.ToString()); Response.End(); } } } AjaxPro.Utility.RegisterTypeForAjax(typeof(Default)); }Silverlightusing System.Json;using System.Collections.ObjectModel;namespace MapClient{ public MainPage() { InitializeComponent(); //和aspx页面相互交互 HtmlPage.RegisterScriptableObject("Page", this); } //和宿主aspx页面交互的函数 [ScriptableMember] public void process(string arg) { //这个arg就是SL从html页面中传递过来的值 }