1. 给input域一个默认值,然后在聚焦的时候清空它
HTML代码
<form id="testform">
    
<input type="text" class="clear" value="Always cleared" />
    
<input type="text" class="clear once" value="Cleared only once" /> 
    
<input type="text" value="Normal text" />
</form>
JavaScript代码
$(function() {

 
//取出有clear类的input域 //(注: "clear once" 是两个class clear 和 once) $('#testform input.clear').each(f$(function() {
//取出有clear类的input域
//(注: "clear once" 是两个class clear 和 once)
$('#testform input.clear').each(function(){
//使用data方法存储数据
$(this).data( "txt", $.trim($(this).val()) );
}).focus(
function(){
// 获得焦点时判断域内的值是否和默认值相同,如果相同则清空
if ( $.trim($(this).val()) === $(this).data("txt") ) {
$(
this).val("");
}
}).blur(
function(){
// 为有class clear的域添加blur时间来恢复默认值
// 但如果class是once则忽略
if ( $.trim($(this).val()) === "" && !$(this).hasClass("once") ) {
//Restore saved data
$(this).val( $(this).data("txt") );
}
});
});
 
2. 预加载图片
);

相关文章:

  • 2021-04-13
  • 2021-12-18
  • 2021-07-15
  • 2021-08-15
  • 2022-12-23
  • 2021-07-12
  • 2021-10-23
猜你喜欢
  • 2022-03-14
  • 2022-12-23
  • 2022-02-14
  • 2021-12-19
相关资源
相似解决方案