JavaScript初步接触
在做一个项目中,接触到了JavaScript,主要是点击一个查询按钮然后弹出一个网页对话框,当在对话框中输入查询条件,点击确定后又返回到原来页面,得出查询结果。
页面如图:
在前台加了一个隐藏的DIV,里面放入两个控件。如下:
<div style="display:none">
<asp:TextBox ID="txtQueryWhere" runat="server"></asp:TextBox>
<asp:Button ID="btnquery" runat="server" Text="Button" OnClick="btnquery_Click" /></div>
前台查询按钮的代码如下:
<input id="Button2" type="button" value="查询" onclick="query()" />
当点击查询按钮时,转到query()函数——JavaScript:
<script language="javascript" type="text/javascript">
function query() {
window.showModalDialog("Query/DeviceQuery.aspx", window, "dialogWidth:700px;dialogHeight:400px;status:no;help:no;scroll:no");
}
</script>
于是就转到上图中的DeviceQuery页面。
按钮“确定”的代码为:
protected void btnOK_Click(object sender, EventArgs e)
{
string swhere = get_where().Replace("'", "\'");
Session["where"] = get_where();
string script = "window.returnValue='true'; window.dialogArguments.__doPostBack('btnquery', '');";
this.ClientScript.RegisterStartupScript(this.GetType(), "MPExecCommand", script, true);
script = "window.close();";
Common.ResponseScript(this.Page, script);
}
注意其中的script字段,里面的__doPostBack('btnQuery','')是返回到页面的btnquery按钮,执行它的Click事件。
相关文档:
貌似CSDN里的都是专业人士,高手可以掠过了,呵呵。
一下是源码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content ......
1.asp.net呼叫js
view
plain
copy
to clipboard
print
?
Response.Write("<mce:script language=javascript><!--
");
Response.Write("alert('欢迎您 ');"
);
Response.Write("location.href='login.aspx';"
)& ......
ECMAScript中,switch语句可以用于字符串,而且能用不是常量的值说明情况:
var BLUE="blue" , RED = "red" , GREEN = "green";
switch(sColor)
{
case BLUE: alert("Blue"); break;
&nb ......
label:statement
例:
start:var iCount = 10;
标签可以被后来的break语句或continue语句引用。
例:
var iNum=0;
outermost:
&n ......
函数
即使函数确实有返回值,也不必明确地声明它。该函数只需要使用return运算符后跟要返回的值即可。
例:
function sum(iNum1, iNum2)
{
  ......