我试图将CSS添加到keyup的输入.如果输入为空,请添加CSS.我试过这个......
$(input).keyup(function() {
var input = $(this).attr('id');
if( input == "" ) {
$(input).css( "border", "1px solid #FB9E25" );
}
});
Run Code Online (Sandbox Code Playgroud)
小智 7
HTML
<input type="text" id="test" />
Run Code Online (Sandbox Code Playgroud)
JS:
$("#test").keyup(function() {
var input = $(this);
if( input.val() == "" ) {
input.css( "border", "1px solid #000" );
}
});
Run Code Online (Sandbox Code Playgroud)
我将它改为黑色,以便更容易看到.
如果你想为多个id做,请尝试:
<form id="some_form">
<input type="text" />
<input type="text" />
</form>
Run Code Online (Sandbox Code Playgroud)
$("#some_form input").each(function() {
$(this).keyup(function() {
var input = $(this);
if( input.val() == "" ) {
input.css( "border", "1px solid #000" );
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6145 次 |
| 最近记录: |