你如何在jQuery函数上传递多个元素?
到目前为止这是我的代码:
HTML
<textarea id="hello">This is the default text</textarea>
<input id="hello2" value="This is another text box">
Run Code Online (Sandbox Code Playgroud)
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');
}
});
});
Run Code Online (Sandbox Code Playgroud)
代替
$('#hello', '#hello2')
Run Code Online (Sandbox Code Playgroud)
使用
$('#hello, #hello2')
Run Code Online (Sandbox Code Playgroud)