-2

大家好,我一直在制作这种具有不同输入但它们都具有相同类的表单:

<input type="text" name="username" class="field" /> 
<input type="text" name="email" calss="field" />  

我想要做的是当输入文件被点击时我想用JQuery改变边框颜色(只有不是同时点击的元素)

有人知道吗?

4

3 回答 3

2

将点击事件绑定到所有输入,然后使用 $(this) 来定位实际被点击的那个。

$('.field').on('click', function() {
     $('.field').removeClass('clicked'); // Remove previous
     var $this = $(this);
     $this.addClass('clicked'); // If you want to add the CSS with a class, which i recommend.
     $this.css('border', '[css-border-values]'); // Inline CSS
});
于 2013-09-27T13:01:51.033 回答
2
<input type="text" name="username" class="field" /> 
<input type="text" name="email" calss="field" />  




$('.field').click(function(){
     $(this).css('attributeName','value'); //here $(this) represents current element.
});
于 2013-09-27T13:00:36.953 回答
0
<input type="text" name="username" class="field" /> 
<input type="text" name="email" calss="field" /> 

$('input[type=text]').focus(function(){
     $('input[type=text]').css({'border':''});
     $(this).css({'border':'solid 2px #ccc'});
});

http://jsfiddle.net/jCpfH/

于 2013-09-27T13:18:10.813 回答