html —— 查看元素属性 与 js 全局属性

来源:互联网 发布:怎么看电脑端口号 编辑:程序博客网 时间:2024/06/11 15:32

算是一个意外的收获,所以记录下。


查看元素的全部属性与事件:

使用 console.log() 打印元素,查看完整属性与事件。


查看js 全局属性与事件:

chrome 浏览器打开console 窗口,watch中 输入" window. "提示的即为全局属性与函数等。


例如,console.log() 打印select 元素,将发现它具有的属性远不止常用的 id,name等,还具有multiple (支持多选),size(最多选取的个数等)。

<select id="select" multiple="multiple" size="2"><option value="1" selected="selected">选项一</option><option value="2" selected="selected">选项二</option><option value="3">选项三</option></select><script type="text/javascript">console.log(document.getElementById("select"))//也可dom操作//document.getElementById("select").multiple=true;//document.getElementById("select").size=2;console.log(document.getElementById("select").selectedOptions[1].innerHTML);//提示:选项二</script>

效果:


要获取选中的多个值,也可通过查看其属性获取。这样是不是比查看示例文档更加有意义?