Prompt isNaN 数组 function DOM window.open/close/location/history
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的更多相关文章
- $(document).ready(function(){})和window.onload=function(){}的比较
这两个函数想必每个前端开发者都不会很陌生,但是很了解用法的人估计就比较少了,博主也是最近才开始注意到这两个函数的区别. 首先$(document).ready(function(){})等同于$(). ...
- 从一个例子了解window.onload、$(function(){})、$(window).load(function(){})的加载顺序
最近遇到一个轮播需求: 1. ajax请求服务器,返回json,判断json数据里每一项中isFix属性是0还是1,0表示不轮播,1表示需要轮播. 2. 当isFix属性为0的时候,表示该图片不轮播, ...
- jq的$(function(){})与window.onload的区别
最近一直在研究jq的源码,书写jq的代码我们通常会包裹在一个$(function(){})函数中,jq的$(function(){})也就是$(document).ready(function(){} ...
- DOM window的事件和方法; Rails查询语法query(查询结构继承); turbolinks的局限;
window.innerHeight 是浏览器窗口可用的高度. window.outerHeight 是浏览器窗口最大的高度. 打开chrome-inspector,上下移动inspector,看到s ...
- 拉动滚动条追加内容,无限延伸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 ...
- (function(){}).call(window) 严格模式匿名函数的this指向undefined
上次在群里,看到有人发出 (function(){}).call(window) 这么一段代码,问这有什么意义,匿名函数中的this不是始终都指向window的么,为什么还要call,我当时也很疑惑. ...
- 【JavaScript学习整理】DOM对象(location history screen navigator)
DOM: 描述网页各个组成部分之间的关系. parentNode: 父节点 childNode: 子节点 firstChild: 第一个子节点 lastChild: 最后一个子节点 nextSibli ...
- window.frames["id"].location使用
由于最近需要维护一个老项目不得不去学习一些自己都没接触过的项目,老项目中虽然技术已经被淘汰,但是思想还是值得去学习探究的,无论是jsp,freemarker,freemarker这些模板引擎还是Vue ...
- $(function(){})与window.onload的区别
不太一样window.onload是在页面所有的元素都加载完成后才触发$(function(){})是在页面的dom结构加载完毕后就触发 dom里的内容不一定都已经加载完成比如说一个页面有好多图片 而 ...
随机推荐
- jquery遍历对象,数组,集合
1.jquery 遍历对象 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTM ...
- IUS通过PLI产生fsdb波形
IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...
- [Ubuntu] Ubuntu DNS服务器配置
服务器IP:10.68.19.61 操作系统:Ubuntu 13.04 DNS程序:Bind9 测试域名:mycloud.com 目标IP:10.68.19.134 配置步骤 1.安装BIND9程序包 ...
- 在linux中的virtualbox无法挂载usb设备的解决方法
方法来源于网络. 在安装完virtualbox之后,virtualbox会建立一个名为 vboxusers 的组,将你的用户名加入到该组即可. 命令参考: #usermod -a -G vboxuse ...
- 【crunch bang】字体美化
中文字体美化是个很讨厌的事情,无数初学者在这里面浪费了无数时间,做了无数没有意义的事情.但这也是不得不做的,我把 Debian/Ubuntu 所需要的中文字体美化操作步骤详细记录在这里,希望能节约大家 ...
- cvWaitKey();
1.函数形式:int cvWaitKey(int delay=0 ): 函数功能:cvWaitKey()函数的功能是不断刷新图像,频率时间为delay,单位为ms. 参数: delay——— ...
- OpenStack 虚拟机监控方案确定
Contents [hide] 1 监控方案调研过程 1.1 1. 虚拟机里内置监控模块 1.2 2. 通过libvirt获取虚拟机数据监控. 2 a.测试openstack的自待组件ceilomet ...
- C++线性方程求解
介绍 程序SolveLinearEquations解决联立方程.该方案需要一个文本文件,其中包含输入和输出方程解决.这个项目是几年前我写在C#中http://www.codeproject.com/A ...
- eclipse运行时编码设置
eclipse运行时编码设置:
- 安装使用RESTful 框架SLIM方法
相关框架: http://www.golaravel.com 是一个PHP框架,内置名为LUMEN的RESTful API框架,有中文文档, http://lumen.golaravel.com/do ...