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里的内容不一定都已经加载完成比如说一个页面有好多图片 而 ...
随机推荐
- csuoj 1395: Timebomb
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1395 1395: Timebomb Time Limit: 1 Sec Memory Limit ...
- [转]java工程师成神之路
转载http://www.hollischuang.com/archives/489https://linux.cn/article-6739-1.html 一.基础篇 1.1 JVM 1.1.1. ...
- 全局函数VS成员函数
#include <iostream> using namespace std; class Test { public: Test(int a, int b) { this->a ...
- Windows平台上安装搭建iPhone/iPad的开发环境
http://www.cnblogs.com/hanxianlong/archive/2015/09/20/4824227.html http://blog.csdn.net/yahohi/artic ...
- II7下配置SSAS通过HTTP 远程链接访问
IIS7下配置SSAS通过HTTP远程连接 安装环境操作系统:Windows7.Windows Server2008IIS版本:7.5 IIS7下配置SSAS通过HTTP远程连接详细的步骤如下:1.首 ...
- 夺命雷公狗---微信开发59----在线点播电影网1之ckplayer播放器
我们节课程就要开始写一个小项目了,这项目主要是写一个在线点播电影影网的,我们用到的播放器是ckplayer ckplayer基本介绍: ckplayer的全称是:超酷flv播放器,他是一款用于网页上播 ...
- PAT乙级 1028. 人口普查(20)
1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...
- C语言初学者代码中的常见错误与瑕疵(4)
问题 小学生数学 很多小学生在学习加法时,发现“进位”特别容易出错.你的任务是计算两个数在相加时需要多少次进位.你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记). 样例: 输入 ...
- Hadoop之TaskInputOutputContext类
在MapReduce过程中,每一个Job都会被分成若干个task,然后再进行处理.那么Hadoop是怎么将Job分成若干个task,并对其进行跟踪处理的呢?今天我们来看一个*Context类——Tas ...
- mysql笔记04 MySQL高级特性
MySQL高级特性 1. 分区表:分区表是一种粗粒度的.简易的索引策略,适用于大数据量的过滤场景.最适合的场景是,在没有合适的索引时,对几个分区进行全表扫描,或者是只有一个分区和索引是热点,而且这个分 ...