[英]text input change class on mouse click
<input type="text" onkeypress="return buyukHarf(event);" class="green" name="f1"/>
is it possible to change the class green
to something else when the area is clicked? 单击该区域时是否可以将green
类别更改为其他类别? Or any other way to change the border color when clicked? 还是单击时更改边框颜色的任何其他方式? Thanks in advance... 提前致谢...
$("input").click(function(){
$(this).removeClass("green").addClass("yellow");
});
In the case of form elements, I'd use focus()
and blur()
over a click()
handler. 对于表单元素,我将在click()
处理函数上使用focus()
和blur()
。
Also, try to avoid using inline javascript as you have done in your example. 另外,请尝试避免像示例中那样使用内联JavaScript。
Focus/Blur example: 焦点/模糊示例:
$("input").focus(function(){
$(this).removeClass("green").addClass("yellow");
}).blur(function(){
$(this).removeClass("yellow").addClass("green");
});
Try this: 尝试这个:
$( "input" ).click( function() {
$( this ).attr( { 'class' : 'anotherClass' } );
} );
Try: 尝试:
$("input[name='f1']").click(function(){
$(this).removeClass("green").addClass("red");
});
OR // for border 或//用于边框
$("input[name='f1']").click(function(){
$(this).removeClass("green").css("border", "1px solid red");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.