简体   繁体   English

提示文字未被删除

[英]Hint text is not being removed

http://jsfiddle.net/udit_sharma/GFknc/ http://jsfiddle.net/udit_sharma/GFknc/

I have created this fiddle.我创造了这个小提琴。 which have a input box and it has hint-Text.它有一个输入框,它有提示文本。 When i am focused in this input box it's hint-Text is being cleared properly.当我专注于此输入框时,提示文本已被正确清除。 and when i focused-out of this input box hint-Text is being showed again if there is nothing entered by user.当我将焦点移出此输入框时,如果用户未输入任何内容,则会再次显示提示文本。

But there is an issue.let say you are focused in input-box and clicked on another tab in the browser now if you comeback to this fiddle again notice that hint-Text is being shown while it was empty while leaving this page.但是有一个问题。假设您现在专注于输入框并单击浏览器中的另一个选项卡,如果您再次回到这个小提琴,请注意提示文本在离开此页面时显示为空。 and also its not clearing this while clicking in and out of the input box.并且在单击输入框和单击输入框外时也不会清除它。 ?

So the issue i found is when i click on another tab onblur is not being called so that variable "valueChanged" is not being set to false.所以我发现的问题是,当我单击另一个选项卡时,不会调用 onblur,因此变量“valueChanged”不会被设置为 false。 So while focusing again it is not clearing the default hint-Text value.因此,在再次聚焦时,它不会清除默认的提示文本值。

So i am not getting why onBlur is not being called.所以我不明白为什么没有调用 onBlur。 If any one have clue about this, please tell or is there any other way to do this functionality?如果有人对此有任何线索,请告诉或是否有其他方法可以执行此功能?

You can try this:你可以试试这个:

<input type="text" name="placeHolder" placeholder="hy i'm a place holder" />

it's an html5 attribute so, you may add the <!DOCTYPE html> on the top of your html file.这是一个 html5 属性,因此您可以在 html 文件的顶部添加<!DOCTYPE html>

Looks like Chrome is firing onblur for the textbox twice.看起来 Chrome 为文本框触发了两次 onblur。 I was able to solve this by making the blur event a named function and binding blur during focus addOptionInputEle.off('blur').on('blur', onAddOptionBlur);我能够通过将模糊事件命名为 function 并在焦点期间绑定模糊来解决这个问题addOptionInputEle.off('blur').on('blur', onAddOptionBlur); . . Then, within onAddOptionBlur I made a loop to unbind all instances of blur handlers.然后,在 onAddOptionBlur 中我做了一个循环来取消绑定模糊处理程序的所有实例。

while(addOptionInputEle.data('events').blur)
{
    addOptionInputEle.off('blur');
}

note: not tested in anything other than chrome.注意:未在 chrome 以外的任何地方进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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