我有onkeydown()
事件的功能,並獲得輸入文本的值長度我按ctrl+a
/阻止一個文本(有5個字符),並鍵入單個字符,但輸出值長度爲輸入是4而不是0。錯誤的輸入文本值長度
function typeInput(that) {
console.log($(that).val().length);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" onkeydown="typeInput(this)">
你提供'that'? 'onkeydown =「typeInput(this)」'它應該是'$(that).val()。length()' – Satpal
@Satpal對不起我的錯誤,那已經有'.val()' – itx