[英]How to get date from innerHTML / textContent javascript
[英]How to get the textContent length of an event
我想檢索事件中的元素數量。
我使用以下功能:
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
如何恢復該值?
為了獲得預期的結果,請使用以下代碼
console.log(event.target.childNodes[0].length)
工作代碼以供參考-https://codepen.io/nagasai/pen/JjPvJoL?editors=1111
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.