简体   繁体   中英

How to know that some text is entered as well as cursor has come out of textbox?

I want to know if there is any event or way to know that some text has been entered into the textarea and also the user has come of the textarea, so that i can invoke some text like "success".

For the some values in the textarea i think we can do through val() function. But how to know that user has come out of the Textarea

My code is like:

<input type="textarea" id="link1"></textarea>
if (!$("#link1").val()) {
    // textarea is empty
}

You can also use $.trim to make sure the element doesn't contain only white-space:

if (!$.trim($("#link1").val())) {
    // textarea is empty or contains only white-space
}

and for detecting when user comes out of textarea

$('#link1').focusout(function() {
    alert(this.id + " focus out");
});

尝试捕获onblur事件,然后检查value.length以查看是否在文本框中添加了一个值。

textarea should be like

<textarea id="link1"></textarea>

events you are searching are onkeyup , onfocus and onblur

使用onKeyPress可以检测到输入了一些文本,而onBlur可以检测到用户来自文本区域

<input type="textarea" id="link1" onBlur = blured() onKeyPress = pressed()></textarea>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM