什么时候?
[0]
是在jquery对象之后添加的,这使您可以直接访问这个jquery对象表示(或包装)的第一个真正的dom元素。对于您的代码,您可以按如下方式将其分解:
/* A JQuery object that reprsents or "wraps" #123 */
const inputJQueryObject = $("#123");
/* Accessing the first true/real DOM element the JQuery object represents */
const inputDOMElement = inputJQueryObject[0];
/* Accessing the current value of the DOM element */
const inputDOMElementValue = inputDOMElement.value;
console.log(inputDOMElementValue);
或者,您可以使用jqueries
.val()
访问当前值的方法
#123
,避免了
[0].value
通过这样做:
console.log( $("#123").val() );
希望有帮助!