Skip to content

Instantly share code, notes, and snippets.

@almond-bongbong
Created September 20, 2018 08:32
Show Gist options
  • Save almond-bongbong/0d431fb71fb4ab1fadbfc1fbc8fcc9ca to your computer and use it in GitHub Desktop.
Save almond-bongbong/0d431fb71fb4ab1fadbfc1fbc8fcc9ca to your computer and use it in GitHub Desktop.
good case
// <input type="text" id="email">
// <input type="text" id="name">
// <input type="text" id="phone">
// <div id="notice"></div>
function show(text) {
document.getElementById('notice').innerHTML = text;
}
function set() {
var a = [
{id: 'email', text: 'email'},
{id: 'name', text: 'name'},
{id: 'phone', text: 'phone'},
];
for (var i = 0; i < a.length; i++) {
let item = a[i];
document.getElementById(item.id).onfocus = function(text) {
return function() {
show(text);
};
} (item.text);
}
}
set();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment