English 中文(简体)
真正简单的javascript tomov Value in text Box
原标题:really simple javascript to remove value in text box

iv 确实是一个简单的javascript问题。 这里有一部分人用问话,但也有类似的方式通过javascript这样做。 基本上,我写了几处文字,这样,当你点击一个具有价值的文本箱时,就算出你能够打出的数值(在大多数用户名箱中,他们在那里没有什么笔记)。 这样做可能有更好的办法(我已经可以认为有些人),这样也能够自由提出。 无论我从哪条手脚看,问题在于,如果用户再次点击所有数据,那么如果他们只是想调整他们可能掌握的东西,以解决这个问题(先在秘密显示代码),即设置一个核对变量,如果是的话。 这是它所期望的。 (t t work, btw)

var unumber = 0;
var pnumber = 0; 

 if(unumber<1){
  $( #username ).click(function(){
  unumber = 1;
  $( #username ).val(  );
 });
 };

 if(pnumber<1){
   $( #password ).click(function(){
   $( #password ).val(  );
   pnumber = 1;
   });
 };

what I m assuming happens is that every time some one clicks the variables are reset, and this leads to a more general question if this is this case, why would the whole script, not just the event handler, run? Im new to javascript so forgive me if this is a stupid question. Anyways, this is a really simple script and there are better and more efficient ways to do it, but how can it be done this way?

最佳回答

不到1人的检查应在点击手里进行。

var unumber = 0;
var pnumber = 0; 

$( #username ).click(function(){
  if(unumber<1){
    unumber = 1;
    $( #username ).val(  );
  }
});

$( #password ).click(function(){
  if(pnumber<1){
     pnumber = 1;
     $( #password ).val(  );
  }
});

值得注意的是,这并不十分有力,它没有处理向田地标。 处理<代码>focus活动。

Another problem is that you don t get the message back if you don t type anything and leave the field. A better approach is to compare against the initial value when the field receives focus. If there s nothing in there when you leave the field, restore to the original value.

http://github.com/mathiasbynens/jQuery-Plugin"。

此外,新的浏览器支持placeholder/code>。 http://www.paciellogroup.com/blog/02/html5-accessibility-chops-the-placeholder-attribute/

问题回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!