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. HDU 2366 Space(二分计数)

    Problem Description During a programming contest, teams cannot sit close to each other, because then ...

  2. BeanFactory

            Spring容器,最基本的接口就是BeanFactory 负责创建,配置,管理bean 它有一个子接口ApplicationContext并将功能扩展.         理论上bean ...

  3. 1029 C语言文法

    program    -> external_declaration | program external_declaration <程序> ->  <外部声明> ...

  4. fault coverage enhancement

    在pseudo-random test中,由于random pattern resistant的特性,fault coverage不是sufficient的, 所以会有一些办法来进行coverage的 ...

  5. Inside TSQL Querying - Chapter 1. Logical Query Processing

    Logical Query Processing Phases Summary (8) SELECT (9) DISTINCT (11) <TOP_specification> <s ...

  6. 锋利的JQuery(一)

    释义: Ajax:Asynchronous Javascript And XML,异步的Javascript和XML 其它库: Prototype:最早 Dojo:学习曲线陡 YUI:比较丰富 Ext ...

  7. Openstack的镜像上传原理

    openstack的horizon的上传镜像流程 通过html的form表单上传文件 先上传到horizon指定的临时目录,存储起来 通过glance-api请求接口 实际上glance-api也是提 ...

  8. Imageloarder

    首先需要加载jar包,和在配置文件中配置Mainactivity.javapackage com.baidu.day13_2imageloader; import com.nostra13.unive ...

  9. 视频处理控件TVideoGrabber中如何混合多个视频源(1)

    其实一个或是几个作为普通的视频源使用的TVideoGrabber组件,可以进行混合来作为一个TVideoGrabber组件使用,这些普通的组件可以是视频捕捉设备或是视频剪辑等.同时这个混合的组件独立于 ...

  10. vsftp黑白名单设置及问题

    问题一:ftpusers和user_list两个文件各自的用途是什么?有何关系? 首先请明确一点:ftpusers不受任何配制项的影响,它总是有效,它是一个黑名单!该文件存放的是一个禁止访问FTP的用 ...