【发布时间】:2011-06-03 06:37:22
【问题描述】:
$(".box_yazi2").each(function () {
var default_value = this.value;
$(this).css('color', '#555'); // this could be in the style sheet instead
$(this).focus(function () {
if (this.value == default_value) {
this.value = '';
$(this).css('color', '#000');
}
});
$(this).blur(function () {
if (this.value == '') {
$(this).css('color', '#555');
this.value = default_value;
}
});
});
这个输入默认值的功能在FF中不起作用,但在IE中完全可以 当然,输入本身看起来像这样:
<input type="text" class="box_yazi2" id="konu" name="konu" value="Boş" />
【问题讨论】:
-
你为什么不用
this.defaultValue? -
最后一行是一组额外的
});。这只是错误地复制粘贴吗? -
@venom 好吧,它适用于 Fx here。
-
Firebug 是否会返回某种错误?另外,如果您只是想完成这项工作(而不是出于学习目的):mucur.name/system/jquery_example
-
@Box9 是的)它是 document.ready 中的最后一个函数))@jensgram 我会试试 thx
标签: javascript jquery html input default-value