zoukankan      html  css  js  c++  java
  • JavaScript 学习(1)--window对象

    JavaScript 学习--Window对象

    window对象方法

    1.1 创建新窗体

    //窗体打开
    var newWindow=Window.open("default.html","windowName","height=200,width=300,..(其他参数)")://height和widht为空默认会打开一个新选项卡
    //窗体关闭
    newWindow.close();
    //窗体的location
    newWindow.location.herf="http://www.baidu.com";
    

    1.2 窗体的对话框

    //提示框
    alert("some text here");
    //带返回值的
    if(confirm("are you sure?")){ //do some thing}
    //带输入框的
    var result=prompt("what is your name?")
    if(result){//do something}
    

    1.3 属性navigator

    navigator.userAgent包含浏览器很多的细节
    比如chrome的userAgent内容有

    document.write(navigator.userAgent);
    //输出入下
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
    

    navigator.appVersion
    5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

    1.4 document

    • document.forms[]
      该值是一个文档中所有form元素对象的数组

    引用其中一个表单可以使用document.forms[0]或者document.forms["formName"]

    • document.images[]

    document对象保持了一个以标记方式插入到文档中的图像的集合,通过document.images可以获得imag元素

    • document.write()

    在载入页面后,浏览器输出流自动关闭,再次之后任何一个对当前页面进行操作的document.write()都将打开一个新的输出流,会清空当前页面内容。所以需要吧HTML内容连接起来赋值给一个变量。需要注意的是document.write()相关的方法document.close(),如果没有进行关闭,连续的document.write()只会连续添加到后面不会清除当前值,如果不添加close方法,就不能显示图像和表单。

    • document.createElement()document.createTextNode()

    document.createElement()在浏览器内存中中创建一个新元素对象
    var p=document.createElement("p")
    document.createTextNode()创建一个新文本节点

    以上操作并不影响本来的文档节点树,需要调用各种插入和替换方法才能将元素放入文档中。

    • document.getElementById('idName')
      获取id为idName的元素
  • 相关阅读:
    体验cygwin纪实
    播布客视频PIT专用播放器MBOO2015
    rpm基本命令参考
    rhel7.x配置本地yum
    mtr网络连通性测试
    Oracle下载汇聚
    Spring Cloud心跳监测
    Hystrix的用法
    Redis系列十:缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级
    dubbo异步调用三种方式
  • 原文地址:https://www.cnblogs.com/keithmoring/p/4225022.html
Copyright © 2011-2022 走看看