开发者

First time a text Input is selected, delete its value

When an element is clicked for the first time, I would like its value to be set to empty.

Does the IF function work in jQuery? Is it like JavaScript?

I only want the data to be erased on the first time, of course, because it will be deleting the default value.

HTML

<input id="Name" class="inputLight" type="text" value="Enter your name here.">

jQuery

$('input').click(function() {
var $this = $(this),
    开发者_开发技巧clickNum = $this.data('clickNum');

if (!clickNum) clickNum = 1;

if(clickNum =1)$this.value = "";

$this.data('clickNum', ++clickNum);
});


You don't need any if statements. You simply want to bind an event which will only be executed once.

Use jQuery's .one() method:

$('input').one('focus', function(){
    this.value = '';
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜