【发布时间】:2011-08-13 23:15:23
【问题描述】:
我想在我的注册表单中使用 jQuery Masked Input Plugin (http://digitalbush.com/projects/masked-input-plugin/)。我的表格是这样的
...
<input class="part1" type="text" name="lname" value="Last Name" onfocus="if(this.value=='Last name') {this.style.color='#aea592';this.style.fontStyle='normal'; this.value=''};" onblur="if(this.value=='') {this.style.color='#aea592'; this.style.fontStyle='italic'; this.value='Last name'}" />
<input class="part2" type="text" id="dob" name="dob" value="Date of Birth" onfocus="if(this.value=='Date of Birth') {this.style.color='#aea592';this.style.fontStyle='normal'; this.value=''};" onblur="if(this.value=='') {this.style.color='#aea592'; this.style.fontStyle='italic'; this.value='Date of Birth'}" />
...
文件的结尾
<script src="core/code/js/mask.js"></script>
<script type="text/javascript">
jQuery(function($) {
$('#dob').mask('99.99.9999', {placeholder:' '});
});
</script>
当您打开页面时,姓氏字段显示“姓氏”一词,但出生日期不显示任何内容。 http://prntscr.com/2miaa我如何才能为 onfocus 事件激活遮罩插件?
【问题讨论】:
-
你真的不应该在整个 HTML 中使用内联 javascript,尤其是不要那么多。
-
你应该阅读unobtrusive JavaScript。