您的位置:首页 > Web前端 > JavaScript

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

2010-09-09 20:52 537 查看
概要:

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

内容:

1使用GetProperty获取脚本对象

对已存在的JS方法调用,比如:

functionHello(message)

{

varresultSpan=$get("result");

resultSpan.innerText="Hello"+message;

}

使用:

ScriptObjecthello=HtmlPage.Window.GetProperty("Hello")asScriptObject;

hello.InvokeSelf(this.input.Text);

2使用CreateInstance创建脚本对象

ScriptObjectscript=HtmlPage.Window.CreateInstance("myHello",this.input.Text);

objectresult=script.Invoke("Display");


3使用HtmlPage.windows.*方法

HtmlPage.Window.Alert(input.Text);//直接输出

HtmlElementr=HtmlPage.Window.Eval("document.getElementById('div')")asHtmlElement;

stringm=r.GetAttribute("innerHTML");

HtmlPage.Window.Alert(m);


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

<scripttype="text/javascript">

functionmyHello(message)

{

$("#result").text("Hello"+message);

}

</script>


ScriptObjectscript=HtmlPage.Window.GetProperty("myHello")asScriptObject;

script.InvokeSelf(this.input.Text);


总结:

实验未成功部分较多,关于js的应用还很弱。在对框架学习后,再仔细复习此篇。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: