JavaScript(2)

var test=parseInt("86abv");
//只解析到86后面abv不解析
var test=parseInt("abc86")
//都不解析

isNaN()判断是否是非数值

if(isNaN("111")){
alert("...");
}//不是非数值
if(isNaN("111aa")){
alert("...");
}//是非数值

定义函数:

function 函数名(参数1,参数2,...){
    //JavaScript语句
    [return返回值]//可以有也可以没有
}
//调用函数
事件名="函数名()";

无参函数例子:

<script>
    function study() {
        for (var index = 0; index < 5; index++) {
            document.write("<h4>欢迎学习JavaScript</h4>");
        }
    }
    </script>
    <input type="button" value="显示5遍欢迎JavaSrcipt" onclick="study()">

带参函数:

<script>
function study(count){
        for (var index = 0; index < count; index++) {
            document.write("<h4>欢迎学习JavaScript</h4>");
        }
    }
    </script>
     <input type="button" value="显示5遍欢迎JavaSrcipt" onclick="study(prompt('请输入显示几次'))">

onclick鼠标单击某个对象
onload一个页面或一幅图像完成加载
onmouseover鼠标移上去
onkeydown某个键盘键被按下
onchange域的内容被改变

BOM浏览器对象模型
window对象
属性:
history有关客户访问的URL信息
location有关当前URL的信息
方法:
confirm()显示带有一个确定和取消按钮的
close()关闭浏览器窗口
open()打开一个新的浏览器窗口
setTimeout()
history对象
方法:
back()前进
forword()后退
location对象
属性:
host设置或返回主机名和URL的端口号
href跳转
reload刷新本页
Document对象
属性:
referrer载入页面的地址
url当前页面地址
方法:
getElementById()第一个对象的引用
getElementsByName()带有指定对象的集合
getElementsByTagName()标签名对象的集合
write()写

猜你喜欢

转载自blog.csdn.net/qq_42844262/article/details/82151418
今日推荐