[英]Enter Key tricks val() length / jQuery
I'm disabling the submit button until something is entered. 在输入内容之前,我将禁用“提交”按钮。 The problem is that the Enter Key is counting as a Character or "length". 问题在于Enter键正在计为字符或“长度”。
This is for a TextArea 这是针对TextArea
Count.js.coffee Count.js.coffee
$(document).ready ->
$(".cmnt_btn").attr "disabled", true
$(".cmnt_area").keyup ->
# Disable button when nothing is entered
# Enter Key tricks this
unless $(this).val().length is 0
$(".cmnt_btn").attr "disabled", false
else
$(".cmnt_btn").attr "disabled", true
# Character Count
left = 300 - $(this).val().length
left = 0 if left < 0
$(".cmnt_counter").text left
How can i "disable" the enter Key counting as a Character or disabling the key until something else is entered ? 我如何“禁用”输入键作为字符计数或禁用该键,直到输入其他内容?
You're probably asking to trim new lines / spaces from the beginning and end of a textarea: 您可能要在文本区域的开头和结尾处修剪新的行/空格:
$(this).val().replace(/^\s+|\s+$/g, '').length
Also, setting true/false on the disabled attribute will do nothing: replace them with prop. 另外,在Disabled属性上设置true / false不会执行任何操作:将它们替换为prop。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.