很多人都向在服务器
端调用客户端的函数来操作,也就是在asp中调用java
script脚本中已经定义好的脚本函数。经过研究,发现了一些勉强的方法。
1.
用Response.Write方法写入脚本
比如在你单击按钮后,先操作数据库
,完了后显示已经完成,可以在最后想调用的地方写上
Response.Write("<script type='text/javascript'>alert();</script>");
这个方法有个缺陷就是不能调用脚本文件
中
的自定义的函数,只能调用内部函数,具体调用自定义的函数只能在Response.Write写上函数定义,比如
Response.Write("<script type='text/javascript'>function
myfun(){...}</script>");
2.
用ClientScript类动态添加脚本
用法如下:在想调用某个javascript脚本函数的地方添加代码,注意要保证MyFun已经在脚本文件中定义过了。
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>MyFun();</script>");
这个方法比Response.Write更方便一些,可以直接调用脚本文件中的自定义函数。
3.
普通的添加控件的Attributes属性
对于普通按钮就是:But ......
很多人都向在服务器
端调用客户端的函数来操作,也就是在asp中调用java
script脚本中已经定义好的脚本函数。经过研究,发现了一些勉强的方法。
1.
用Response.Write方法写入脚本
比如在你单击按钮后,先操作数据库
,完了后显示已经完成,可以在最后想调用的地方写上
Response.Write("<script type='text/javascript'>alert();</script>");
这个方法有个缺陷就是不能调用脚本文件
中
的自定义的函数,只能调用内部函数,具体调用自定义的函数只能在Response.Write写上函数定义,比如
Response.Write("<script type='text/javascript'>function
myfun(){...}</script>");
2.
用ClientScript类动态添加脚本
用法如下:在想调用某个javascript脚本函数的地方添加代码,注意要保证MyFun已经在脚本文件中定义过了。
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>MyFun();</script>");
这个方法比Response.Write更方便一些,可以直接调用脚本文件中的自定义函数。
3.
普通的添加控件的Attributes属性
对于普通按钮就是:But ......
最近要用到相关技术,先贴在这,有空再翻页。
本文转自:
http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4399
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/JavaScript-Calls-from-C.htm
http://www.codeproject.com/KB/COM/jscalls.aspx
Introduction
Sometimes, when we are using the IE Browser Control inside of a C++ application, we need to access the HTML elements. We can do it by using standard COM objects such as IWebBrowser2 , IHTMLDocument2 , and so forth. By doing this, we easily can implement features such as click button, click anchor, get input string, get HTML text, and so on. Unfortunately, Microsoft did not provide similar objects for JavaScript. In any case, it is possible to make a control for the JavaScript object inside an HTML page by using a traditional COM approach. This article describes the class CWebPage that allows you to do it and a technique to call a JavaScript function from C++ code.
How to Do This
As the result of using the presented ......
最近要用到相关技术,先贴在这,有空再翻页。
本文转自:
http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4399
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/JavaScript-Calls-from-C.htm
http://www.codeproject.com/KB/COM/jscalls.aspx
Introduction
Sometimes, when we are using the IE Browser Control inside of a C++ application, we need to access the HTML elements. We can do it by using standard COM objects such as IWebBrowser2 , IHTMLDocument2 , and so forth. By doing this, we easily can implement features such as click button, click anchor, get input string, get HTML text, and so on. Unfortunately, Microsoft did not provide similar objects for JavaScript. In any case, it is possible to make a control for the JavaScript object inside an HTML page by using a traditional COM approach. This article describes the class CWebPage that allows you to do it and a technique to call a JavaScript function from C++ code.
How to Do This
As the result of using the presented ......
javascript如何定义类呢?
面试的时候有学生被问到这个问题。
实际上javascript的方法就是一个对象。
利用这一点,我们可以使用javascript定义类。
如下例子所示。
<mce:script language="javascript"><!--
//javascript的面向对象的例子
function sayHi(){
alert("Hello ,"+this.name);
}
function getAge(){
alert("my age:"+this.age);
}
function Student(name,age){
var tempStu=new Object;
//属性
tempStu.name=name
tempStu.age=age;
//方法
tempStu.sayHi=sayHi;
tempStu.getAge=getAge;
return tempStu;
}
var s =Student("jack",20);
s.sayHi();
s.getAge();
// --></mce:script>
定义类有好几种方式。以上只是其中一种。大家可以在人民邮电,《javascript高级程序设计》
一书去找到更多方法。 ......
javascript集锦
javascript数组操作汇总
javascript动态创建form表单 和 节点控制说明
动态读取
javascript:function ctys(_ctag){
ctys1=document.createElement(_ctag);
document.body.appendChild(ctys1);
return ctys1
};
newE1=ctys('<TEXTAREA id=www>');
newE1.cols='150';
newE1.rows='30';
newE2=ctys('BUTTON');
newE2.value="执行";
newE2.onclick=function(){
eval(document.getElementById("www").value)
};
alert(1)
动态页面控制示例
javascript:document.write(document.getElementsByTagName('body')(0).innerHTML.match(/<SPAN class=fcgray>([\s\S]*?)<\/SPAN>/ig))
javascript:alert(document.getElementById('tab_c_iframe').style.display="none")
javascript:alert(document.getElementsByTagName('body')(0).innerHTML)
javascript:document.write(document.getElementsByTagName('body')(0).innerHTML)
javascript:var ccc=document.createElement("div");ccc.setAttribute("type","text");ccc.setAttribute
("value","11111111111111");ccc.style.marginLeft="8px";ccc ......
1.call方法
官方(JavaScript手册):
调用一个对象的一个方法,以另一个对象替换当前对象。
call([thisObj[,arg1[,
arg2[, [,.argN]]]]])
参数
thisObj 可选项。将被用作当前对象的对象。
arg1, arg2, , argN
可选项。将被传递方法参数序列。
说明
call 方法可以用来代替另一个对象调用一个方法。call
方法可将一个函数的对象上下文从初始的上下文改变为由thisObj指定的新对象。
如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj。
2.apply方法
官方(JavaScript手册):
应用某一对象的一个方法,用另一个对象替换当前对象。
apply([thisObj[,argArray]])
参数
thisObj 可选项。将被用作当前对象的对象。
argArray 可选项。将被传递给该函数的参数数组。
说明
如果 argArray 不是一个有效的数组或者不是 arguments 对象,那么将导致一个 TypeError。
如果
没有提供 argArray 和 thisObj 任何一个参数,那么 Global 对象将被用作 thisObj, 并且无法被传递任何参数。
两者的区别:
两
者实现的功能是完全一样的,只是参数传递方式不一样,call是将各个参数以逗号(,)隔 ......
JavaScript 时间加减:
<HTML>
<BODY>
<script type="text/javascript">
var time = new Date("04/30/2010");
document.write(time);
document.write("<br>");
//plus two days
var haomiao = time.getTime() +2*24*60*60*1000;
var plustime = new Date(time.setTime(haomiao));
document.write(plustime);
</script>
</BODY>
</HTML>
JavaScript 时间改变:
<HTML>
<HEAD>
</HEAD>
<BODY>
<script type="text/javascript">
//now time
var nowtime = new Date();
  ......