jQuery not(),忽略某些命名元素
希望你能帮助我!
我有一个表单,其中有大量的输入
。这些输入的初始类为 inputLight
,它使用浅灰色文本。我有以下 jQuery 代码,在 focus
上将文本颜色更改为 inputDark
,在 blur
上将其更改回来:
$('input').focus(function(){
$(this).attr('class', 'inputDark');})
.blur(function() {$(this).attr('class', 'inputLight');
这绝对有效。我还有以下代码,用于在首次选择输入时删除输入的值。
/* First time only, delete default text*/
$('input').one('focus', function(){
$(this).val('');});
这也有效。我要去哪里?好吧,我有两个 input
按钮,一个用于提交表单,一个用于清除表单 - 但我的问题不在于验证。
当用户单击任一按钮时,它当然会删除其值。并更改文本的颜色。
我不希望这两个按钮发生任何事件,这些按钮名为 Submit Button
和 Clear Button
。
我尝试使用:
/* Toggle gray/black text */
$('input').not('input[name=Submit Button]').not('input[name=Clear Button]').focus(function() {$(this).attr('class', 'inputDark');}).blur(function() {$(this).attr('class', 'inputLight'); });
和:
/* First time only, delete default text*/
$('input').not('input[name=Submit Button]').not('input[name=Clear Button]').one('focus', function(){
$(this).val('');
});
抱歉,那里的标记很糟糕,我知道它看起来一定很糟糕。
有了 .not()
函数,这两个函数都不起作用,但按钮起作用。去掉 .not()
效果就可以了,但是按钮失控了。
有人可以帮我吗?
hope you can help me!
I have a form, which has a large amount of inputs
. These inputs have the initial class of inputLight
, which uses light grey text. I have the following jQuery code to, on focus
change the colour of text to inputDark
, and on blur
to change it back:
$('input').focus(function(){
$(this).attr('class', 'inputDark');})
.blur(function() {$(this).attr('class', 'inputLight');
This absolutely works. I also have the following code to delete the value of an input
when it is first selected.
/* First time only, delete default text*/
$('input').one('focus', function(){
$(this).val('');});
That works too. Where am I going with this? Well, I have two input
buttons, one for submitting the form and one for clearing it - but my problem lies not with validation.
When the user clicks either button, it of course, deletes it's value. And changes the colour of the text.
I don't want either event to happen to these buttons, which are named Submit Button
and Clear Button
.
I tried using:
/* Toggle gray/black text */
$('input').not('input[name=Submit Button]').not('input[name=Clear Button]').focus(function() {$(this).attr('class', 'inputDark');}).blur(function() {$(this).attr('class', 'inputLight'); });
and:
/* First time only, delete default text*/
$('input').not('input[name=Submit Button]').not('input[name=Clear Button]').one('focus', function(){
$(this).val('');
});
Sorry for the bad markup there, I know it must look terrible.
With the .not()
functions in there, neither function works, but the buttons work. Take out .not()
and the effects work, but the buttons go haywire.
Can anyone help me here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$('input:text')
不是更有效率吗?wouldn't
$('input:text')
be more productive?