vs2010 学习Silverlight学习笔记(18):JavaScript

概要:

       此篇主要学习SL中关于JS的应用。

内容:

1使用GetProperty获取脚本对象

        对已存在的JS方法调用,比如:
        function Hello(message)
        {
        var resultSpan = $get("result");
        resultSpan.innerText = "Hello " + message;
         }
      使用   : 
ScriptObject hello = HtmlPage.Window.GetProperty("Hello") as ScriptObject;
         hello.InvokeSelf(this.input.Text);

2使用CreateInstance创建脚本对象

   ScriptObject script = HtmlPage.Window.CreateInstance("myHello",this.input.Text);
      object result = script.Invoke("Display");
 
3使用HtmlPage.windows.*方法
            HtmlPage.Window.Alert(input.Text);//直接输出
HtmlElement r = HtmlPage.Window.Eval("document.getElementById('div')")as HtmlElement;
            string m = r.GetAttribute("innerHTML");
            HtmlPage.Window.Alert(m);

 

4对ajax等的支持,以jQuery为例:

        <script type="text/javascript">
        function myHello(message)
        {
               $("#result").text("Hello " + message);
        }
        </script>
 
ScriptObject script = HtmlPage.Window.GetProperty("myHello") as ScriptObject;
        script.InvokeSelf(this.input.Text);
 

总结:

       实验未成功部分较多,关于js的应用还很弱。在对框架学习后,再仔细复习此篇。

posted @ 2010-09-09 20:52  耀哥  阅读(775)  评论(0编辑  收藏  举报