JS日常

发布于 2017-05-13  211 次阅读


js 获取input type="file" 选择的文件大小、文件名称、上次修改时间、类型等信息

<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title></title>  
</head>  
<body>  
    <form id="form1" runat="server">  
        <div>  
            <input type="file" name="f" id="f" />  
            <input type="button" name="aa" id="aa" value="测试" onclick="javascript: _s();" />  
        </div>  
    </form>  
</body>  
</html>  
<script type="text/javascript">  
    function _s() {  
        var f = document.getElementById("f").files;  
        //上次修改时间  
        alert(f[0].lastModifiedDate);  
        //名称  
        alert(f[0].name);  
        //大小 字节  
        alert(f[0].size);  
        //类型  
        alert(f[0].type);  
    }  
</script>

*多个文件会存储在files数组中

js 获取Object对象长度

var bookAuthors = {
    "Farmer Giles of Ham": "J.R.R. Tolkien",
    "Out of the Silent Planet": "C.S. Lewis",
    "The Place of the Lion": "Charles Williams",
    "Poetic Diction": "Owen Barfield"
};

var arr = Object.keys(bookAuthors);

//Outputs: Array [ "Farmer Giles of Ham", "Out of the Silent Planet", "The Place of the Lion", "Poetic Diction" ]
console.log(arr);

//Outputs: 4
console.log(arr.length);

例如在ul下游多个li元素,如何获取这些li元素的倒数第二个li

$("li").eq(-2)

梦想还是要有的,万一实现了呢