c#和javascript交互
在asp.net開發中,經常會用到後台和前台的交互,就此總結了一點c#和javascript相互操作的方法
1.在後台c#代碼中調用jacascript的方法
javascript代碼:
<script type="text/javascript" language="javascript">
function test()
{
alert("oec2003");
return false;
}
</script>
c#代碼:
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>");
}
2.javascript中調用c#方法
如果c#中的方法有返回值,可以用下面方法
c#代碼
public string GetAuthStatus()
{
ViewState["Auth"] = "Red";
return ViewState["Auth"].ToString();
}
javascript代碼
function getAuth()
{
var authStatus="<%=GetAuthStatus()%>";
return authStatus;
}
如果在javascript調用的c#方法沒有返回值,可以在一面中放一個button,然後在button的單擊事件中去寫想做的事情,在客戶端的腳本中寫下如下代碼就可以了
document.all("button1").click();
相关文档:
10、mootools.js的写类方式
mootools.js的最新版本是1.2.3,这里使用的是1.2.0。mootool被设计成非常紧凑的,模块化的,面向对象的的js库。mootool中写类用Class类。Class类由Native类new出来的:
/*
*Script: Class.js
*/
var Class = new Native({
name: 'Class',
initialize: function(properties){
propert ......
Do you want an ultra fast web site? Get JSL and optimize your JavaScript loading now!
Imagine there's a 4-lane highway between your web browser and the internet itself. This highway is optimize to let pictures, text, and css fly by. But, when it comes to external scripts, the highway crea ......
首先是十个JS FRAMEWORK
jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
jquery UI
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
Chrome Frame
<script src=& ......
1.javascript与Html中的调用问题。
在javascript中要想更改html中的一些属性值,特别是在页面内容较多时,务必使用document.getElementById(id)的方式进行,否则javascript将不能更改属性!
2.Date类。
在Date类中的getMonth()等方法返回值为number。因此可以使用数组存储月份信息如month=[“1月”,&ldq ......