2013-07-09 28 views
0

如何傳遞jQuery函數中的多個元素?在jQuery函數中傳遞多個ID

這是到目前爲止我的代碼:

HTML

<textarea id="hello">This is the default text</textarea> 
<input id="hello2" value="This is another text box"> 

的JavaScript

$(function() { 
    $('#hello', '#hello2').each(function() { 
     $.data(this, 'default', this.value); 
    }).focus(function() { 
     if (!$.data(this, 'edited')) { 
      this.value = ""; 
     } 
    }).change(function() { 
     $.data(this, 'edited', this.value != ""); 
    }).blur(function() { 
     if (!$.data(this, 'edited')) { 
      this.value = $.data(this, 'default'); 
     } 
    }); 
}); 

演示:http://jsfiddle.net/eJP9C/252/

回答