我想检索事件中的元素数量。
我使用以下功能:
element.bind('keyup', function (event) {
console.log(event);
});
console.log(事件)重新设置了一个这样的对象(缩短了渲染的对象)
n.Event {originalEvent: KeyboardEvent, type: "keyup", isDefaultPrevented:
ƒ, timeStamp: 13561.044999980368, jQuery2140638708200199875: true, …}
altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
...
scrollTop: 0
scrollWidth: 1035
shadowRoot: null
slot: ""
spellcheck: true
style: CSSStyleDeclaration {alignContent: "", alignItems: "", alignSelf: "",
alignmentBaseline: "", all: "", …}
tabIndex: 0
tagName: "DIV"
textContent: "abc"
title: ""
translate: true
...
在这个对象中,我想在变量中检索textContent的长度值
textContent: "abc"
这里是一个例子:
https://codepen.io/gregand/pen/PoYevYQ?editors=1111
如何恢复该值?
答案 0 :(得分:2)
要获得预期的结果,请使用以下代码
console.log(event.target.childNodes[0].length)
工作代码以供参考-https://codepen.io/nagasai/pen/JjPvJoL?editors=1111