如何清除焦点上的文本框? [英] How to clear a textbox onfocus?
本文介绍了如何清除焦点上的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试过了,但是不起作用:
I've tried this but it doesn't work:
$(function() {
$('input[type=text]').focus(function() {
$(this).val() == '';
});
});
推荐答案
要设置该值,您必须将新值作为参数传递.使用.val()jQuery函数,这是一件时髦的事情.
To set the value, you have to pass the new value as a parameter. This is a funky thing with the .val() jQuery function.
$(this).val('')
看看 jQuery API 并搜索"val"
take a look at the jQuery API and search for 'val'
这篇关于如何清除焦点上的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文