Created
March 30, 2015 09:42
-
-
Save imEhllBdPGMVaArZ/d22eb44bd1ddf7218d02 to your computer and use it in GitHub Desktop.
placeholder的积累,看下情况
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Placeholder | |
$('input[aria-label]').each(function() { | |
var current = $(this); | |
var flag = !!current.attr('aria-label'); | |
if(flag) { | |
$('<span class="placeholder">'+current.attr('aria-label')+'</span>').appendTo(current.parent()) | |
}; | |
current.on("focus", function() { | |
current.siblings(".placeholder").hide(); | |
}); | |
current.siblings(".placeholder").on('click', function() { | |
if(flag) { | |
$(this).hide(); | |
current.focus(); | |
} | |
}); | |
current.on('blur', function() { | |
if(current.val() == '' || current.val() == current.attr('aria-label')) { | |
current.siblings('.placeholder').show(); | |
} | |
}); | |
}); | |
</script> | |
<div class="input_wrap clearfix"> | |
<label class="input_label"><i class="required">*</i>所属营业部:</label> | |
<div class="input_control"> | |
<input type="text" name="" id="" class="input_txt" value="" aria-label="你所在营业部全称"> | |
<span class="placeholer">这个占位符文本就是jquery生成的,通过读取aria-label来操作</span> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment