美文网首页
浏览器常用的输出方式

浏览器常用的输出方式

作者: Leonard被注册了 | 来源:发表于2019-11-20 09:50 被阅读0次

    console.xxx

    • console.log()
    let a = 10;
    console.log(a);    // 10
    
    • console.dir():输出一个对象的详细键值对信息
    console.dir(document.body);  
    
    • console.table():把一个多维JSON数组在控制台按照表格的方式呈现出来
    let b = [{
      id: 1,
      name: '张三'
    },{
      id: 2,
      name: '李四'
    }]
    console.table(b);
    
    console.table输出结果

    浏览器窗口弹窗

    • alert/confirm/prompt三种方式输出的结果都必先经过toString转换为字符串,都会阻断JS代码的执行,只有窗口关掉,才会继续执行
    alert(100);   // '100'
    
    // 确定和取消:选择性弹框
    confirm('Are you sure?');
    
    // 在confirm基础上多了一个输入框
    prompt('Are you sure?');
    

    document.write

    • 在页面中写入信息,和alert一样,输出的结果都是字符串,并且写入内容将覆盖原页面
    document.write({name:'23333'});  // [object Object]
    

    相关文章

      网友评论

          本文标题:浏览器常用的输出方式

          本文链接:https://www.haomeiwen.com/subject/hlwnictx.html