onBlur 和 onFocus 位于单独的 jQuery 中
这个 jQuery 不起作用。我知道这看起来有点奇怪。但我怎样才能让它发挥作用呢?
JavaScript 部分中的 CSS 修改不起作用。在 .blur 上,如果字段中没有任何内容,则 jQuery 应更改文本框的颜色。
在模糊
上,如果字段中没有任何内容,则文本应该更改并且文本颜色应该更改。在焦点
上,如果字段中存在“搜索范围”,则文本应更改且文本颜色应更改。
我必须删除内联 JavaScript 吗?
This jQuery isn't working. I know it looks kind of odd. But how can I get it to work?
The CSS modifications in the JavaScript section are not functioning. On .blur if the field has nothing in it, the jQuery should change the color of the text box.
On the blur
if there is nothing in the field, the text should change and the text color should change. On the focus
if there is "Search Within" in the field, the text should change and the text color should change.
Do I have to remove the inline JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试一下,看看是否可以解决问题:
http://jsfiddle.net/GhA2u/
try this and see if it fixes the problem :
http://jsfiddle.net/GhA2u/
您必须删除内联代码,因为它在事件处理程序之前运行。
您应该保留 HTML 仅用于表示,所有逻辑和 JavaScript 都放在
标记内和 .JS 文件中甚至更好。
修复了 JSFiddle
JQuery
HTML
you will have to remove the inline code, because it runs before the event handlers.
You should keep the HTML for persenation only, All the logic and JavaScript put inside the
<script>
tag and in a .JS file is even better.fixed JSFiddle
JQuery
HTML
通过 Firebug 运行代码并查看 css 属性/属性是什么。内联应该覆盖 javascript 属性设置/css 样式属性,除非您使用重要!属性。
Run the code through Firebug and see what the css properties/attributes are. Inline should override javascript attribute settings/css styling attributes, unless you use the Important! attribute.
我最好的猜测是内联函数首先运行,因此当该字段为空并且您单击时,它会被设置为具有内联函数的内容。因此,无论如何,当调用 jquery onblur 时,该字段中始终包含文本(因为即使没有文本,并且调用 onblur 时,内联函数也会在 jquery 运行之前添加文本)。
您能详细说明一下您希望发生什么吗?也许我可以帮忙。
My best guess is that the inline functions are running first, so when the field is blank and you click out, it is set to something with the inline function. So not matter what, when the jquery onblur is called, the field always has text in it (because even when it doesn't and the onblur is called the inline function adds text before the jquery runs).
Could you elaborate on what you want to occur? Maybe I can help.