1、prompt的利用

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" /> </div>
</form>
</body>
</html>
<script>
document.getElementById("Button1").onclick = function ()//Button1的点击事件
{
var a = prompt("请输入内容");//接受prompt的值的内容赋值给a
document.getElementById("Label1").innerHTML = a;//把a赋值给label1
return false;//阻止页面刷新。如果没有这个,页面就会回到刚开始页面加载的样子
} </script>

2、JS中数字和文本的结合的输出结果

<script>
document.getElementById("Button1").onclick = function ()//Button1的点击事件
{
var a = "";
var b = ;
var c = ;
alert(a + b + c);//返回102030
alert(b + c + a);//
alert(b + a + c);//
alert(parseInt(a) + b);//输出30,注意parseInt()方法
alert(b.toString()+a);//输出2010
alert(b+""+c);//输出2030,注意中间的"". }

3、JS保证文本框内只有数字(isNaN())

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div>
</form>
</body>
</html>
<script>
document.getElementById("TextBox1").onkeyup = function ()
{ if (isNaN(this.value))//“不是一个纯数字?”true表示“不是一个数字”,false表示是一个数字
{
this.value = this.value.substr(,this.value.length-);//文本框的值只保留数字部分
}
} </script>

4、JS下 for(i in "aaa") {alert(i);}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div>
</form>
</body>
</html>
<script>
document.getElementById("Button1").onclick = function ()
{
var a = "asdfg";
for (i in a)
{
alert(i);//依次弹出a的所有索引号0,1,2,3,4
} } </script>

5、JS 下数组的建立,添加和取值   var al = new Array(); 数组的数量用length

<script>
document.getElementById("Button1").onclick = function ()
{
var al = new Array();//建立JS的数组,相当于C#的集合,不限长度,不限数据类型
al[0] = 1;//给数组添加数据
al[1] = "2";//给数组添加数据
var b = al[1];//取数组内的某一个值
}
</script>

6、JS的函数function(){}

<script>

    function aaa(a,b)//aaa为函数名称 a,b为根据需要添加的参数,不用在此限制ab的数据类型
{
alert("a"); //执行语句
//根据具体情况看有没有需要rerurn,有就写上,没有就不用谢。
}
function bbbb()//没有参数的函数bbb
{
执行语句
}
</script>

7.DOM获取元素方式

<script>

    var a = document.getElementById("Id值");//按照Id获取元素,获得一个元素
var b = document.getElementsByClassName("Class值");//按照Class获取,获得一堆元素,返回一个集合
var c = document.getElementsByTagName("元素名");//按照元素名称获取,获得一堆元素,返回一个集合
//什么是元素名?比如div img span input,注意button不是
var d = document.getElementsByName("name值");//按照name称获取,获得一堆元素,返回一个集合,name是给服务端用的
//后两者在实际中不实用,后两者实现的效果,前两者都能实现,而且更准备
</script>

8、window.open()的各项参数

<script>
window.open("page.html", "_blank", "height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //该句写成一行代码
//参数解释:
//window.open 弹出新窗口的命令;
//'page.html' 弹出窗口的文件名;
//'_blank' 弹出d到新的空的窗口
//height=100 窗口高度;
//width=400 窗口宽度;
//top=0 窗口距离屏幕上方的象素值;
//left=0 窗口距离屏幕左侧的象素值;
//toolbar=no 是否显示工具栏,yes为显示;
//menubar,scrollbars 表示菜单栏和滚动栏。
//resizable=no 是否允许改变窗口大小,yes为允许;
//location=no 是否显示地址栏,yes为允许;
//status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
</script>

9、window.history

<script>
window.history.back();//向后退一个界面
window.history.forward();//向前进一个界面
window.history.go(n);//n为int类型,-1表示向后退一个界面,1表示向前进一个界面
</script>

10、window.location.href

<script>
var a = window.location.href;//获取当前页面的地址
window.location.href("http://www.baidu.com");//只能在本页面重新打开百度页面,如果要单独打开新页面,必须用window.open();
</script

完!!

Prompt isNaN 数组 function DOM window.open/close/location/history的更多相关文章

  1. $(document).ready(function(){})和window.onload=function(){}的比较

    这两个函数想必每个前端开发者都不会很陌生,但是很了解用法的人估计就比较少了,博主也是最近才开始注意到这两个函数的区别. 首先$(document).ready(function(){})等同于$(). ...

  2. 从一个例子了解window.onload、$(function(){})、$(window).load(function(){})的加载顺序

    最近遇到一个轮播需求: 1. ajax请求服务器,返回json,判断json数据里每一项中isFix属性是0还是1,0表示不轮播,1表示需要轮播. 2. 当isFix属性为0的时候,表示该图片不轮播, ...

  3. jq的$(function(){})与window.onload的区别

    最近一直在研究jq的源码,书写jq的代码我们通常会包裹在一个$(function(){})函数中,jq的$(function(){})也就是$(document).ready(function(){} ...

  4. DOM window的事件和方法; Rails查询语法query(查询结构继承); turbolinks的局限;

    window.innerHeight 是浏览器窗口可用的高度. window.outerHeight 是浏览器窗口最大的高度. 打开chrome-inspector,上下移动inspector,看到s ...

  5. 拉动滚动条追加内容,无限延伸document高度 $(window).scroll(function(){if($(window).scrollTop() + $(window).height() == $(document).height()) { $("body").append(html) } })

    $(document).ready(function() { // endless scrolling $(window).scroll(function() { if($(window).scrol ...

  6. (function(){}).call(window) 严格模式匿名函数的this指向undefined

    上次在群里,看到有人发出 (function(){}).call(window) 这么一段代码,问这有什么意义,匿名函数中的this不是始终都指向window的么,为什么还要call,我当时也很疑惑. ...

  7. 【JavaScript学习整理】DOM对象(location history screen navigator)

    DOM: 描述网页各个组成部分之间的关系. parentNode: 父节点 childNode: 子节点 firstChild: 第一个子节点 lastChild: 最后一个子节点 nextSibli ...

  8. window.frames["id"].location使用

    由于最近需要维护一个老项目不得不去学习一些自己都没接触过的项目,老项目中虽然技术已经被淘汰,但是思想还是值得去学习探究的,无论是jsp,freemarker,freemarker这些模板引擎还是Vue ...

  9. $(function(){})与window.onload的区别

    不太一样window.onload是在页面所有的元素都加载完成后才触发$(function(){})是在页面的dom结构加载完毕后就触发 dom里的内容不一定都已经加载完成比如说一个页面有好多图片 而 ...

随机推荐

  1. csuoj 1395: Timebomb

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1395 1395: Timebomb Time Limit: 1 Sec  Memory Limit ...

  2. linux第7天 I/O的五种模型, select

    服务器端避免僵尸进程的方法: 1)通过忽略SIGCHLD信号,解决僵尸进程 signal(SIGCHLD, SIG_IGN) 2)通过wait方法,解决僵尸进程 signal(SIGCHLD, han ...

  3. 【py网页】sitecopy代码

    001 #coding:utf-8 002 import re,os,shutil,sys 003 import urllib2,socket,cookielib 004 from threading ...

  4. BPM 应用系统开发案例实战

    概述 IBM BPM 的前身是 Lombardi,是由 IBM 于 2009 年收购的产品,之后产品更名为 IBM WebSphere Lombardi Edition,目前最新版本称为 IBM BP ...

  5. YUI Reset CSS (学习摘抄)

    正在使用CSS的你,用过CSS Reset吗?当然,或许你用了,却不知道正在用,比如你可能用到: *{    margin: 0;    border: 0;    padding: 0;   } 这 ...

  6. MySQL 添加列,修改列,删除列

    ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table ...

  7. Intellij IDEA

    http://1358440610-qq-com.iteye.com/blog/2102195

  8. PHP 页面编码声明与用header或meta实现PHP页面编码的区别

    php的header来定义一个php页面为utf编码或GBK编码 php页面为utf编码 header("Content-type: text/html; charset=utf-8&quo ...

  9. Mysql ibdata 丢失或损坏如何通过frm&ibd 恢复数据

    mysql存储在磁盘中,各种天灾人祸都会导致数据丢失.大公司的时候我们常常需要做好数据冷热备,对于小公司来说要做好所有数据备份需要支出大量的成本,很多公司也是不现实的.万一还没有做好备份,数据被误删除 ...

  10. Greenplum的全量备份之gpcrondump

    gpcrondump是对gp_dump的一个包装,可以直接调用或者从crontab中调用.这个命令还允许备份除了数据库和数据之外的对象,比如数据库角色和服务器配置等. gpcrondump 常用到的参 ...