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事件。
相关文档:
js eval
eval函数接收一个参数s,如果s不是字符串,则直接返回s。否则执行s语句。如果s语句执行结果是一个值,则返回此值,否则返回undefined。
例子
直接运算
alert(eval('1+2')); // ->3
赋值
eval('var aa = 5');
alert(aa); // ->5
类型转换
var yy = "{a:'aa',b:'bb'}";
yy = eval('(' + yy + ')');
......
javascript页面跳转常用代码
按钮式:
<INPUT name="pclog" type="button" value="GO" onClick="location.href='http://www.163.com'">
或者
<input type="button" value="重新购买" onclick="return goBack ......
在javascript控制div之间的外边距时,代码写到
document.getElementById("").style.marginTop=20;
这个在IE浏览器中可以,但是在chrome中就不行,这个问题是应该
document.getElementById("").style.marginTop="20px";
各个浏览器中不同的问题要求不等对待,这些天学了div+css在设置各个浏览器是不同的配置,要针对每个 ......
ASP.NET中前台javascript与后台代码调用
2010-03-31 10:01
.net中C#代码与javaScript函数的相互调用问题。
问:
1.如何在JavaScript访问C#函数?
2.如何在JavaScript访问C#变量?
3.如何在C#中访问JavaScript的已有变量?
4.如何在C#中访问JavaScript函数?
问题1答案如下:
javaScript函 ......
JavaScript以ECMAScript标准作为功能基准,ECMAScript有5种原型类型:Undefined,Null,Boolean,Number和String。
可以用typeof来判断类型,例:
var sTemp = "test string";
alert(typeof sTem ......