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事件。
相关文档:
JavaScript中没有Trim函数,VBScript语言中才有这个函数,就是去掉字符串头和尾的空格。可以在JavaScript中这么写一个:
<script language="JavaScript">
//此处为string类添加三个成员
String.prototype.Trim = function(){ return Trim(this);}
String.prototype.LTrim = function(){return LTrim( ......
with语句
用于设置代码特定对象的作用域。
例:
var sMessage = "hello world";
with(sMessage)
{
&nbs ......
函数
即使函数确实有返回值,也不必明确地声明它。该函数只需要使用return运算符后跟要返回的值即可。
例:
function sum(iNum1, iNum2)
{
  ......
引用类型通常叫做类(class),遇到引用值时,所处理的就是对象。
对象的创建:
var o = new Object();
如果没有参数可以省略括号,如:var o = new Object;
Object类:
&nb ......