您想解释一下之间的区别吗?
document.getElementById("something")
Run Code Online (Sandbox Code Playgroud)
和
$("#something")
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用ajax上传文档,我意识到了这一点
var upl = document.getElementById('uplFile');
console.log(upl.files);
Run Code Online (Sandbox Code Playgroud)
返回一个对象但是
var upl = $('#uplFile');
console.log(upl.files);
Run Code Online (Sandbox Code Playgroud)
返回"未定义"
请解释一下差异.
我认为你的意思是:
document.getElementById("something")
Run Code Online (Sandbox Code Playgroud)
和
$('#something')
Run Code Online (Sandbox Code Playgroud)
第一个将返回具有指定id的DOM元素,或者为null.
第二个将返回一个jQuery对象,它将包含具有指定id的DOM元素,或者是一个空的jQuery对象(length = 0).
由于jQuery函数返回jQuery对象而不是元素,因此必须从jQuery对象中获取元素以访问元素属性:
var upl = $('#uplFile');
console.log(upl[0].files);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |