【发布时间】:2011-11-08 05:39:24
【问题描述】:
目前我有一个输入框,其值为“当前网站”
当他们点击它时,我运行这个函数:
function clearMeHttp(formfield) {
if (formfield.defaultValue == formfield.value) {
formfield.value = "http://";
}
};
如果您单击该框,它可以正常工作,但是如果您进入该框,它只会突出显示“http://”这个词,这会破坏它的目的,除非他们按下我想要避免的右箭头键。
谢谢!
这是另一个代码:<input onblur="restoreMe(this)" onfocus="clearMeHttp(this)" type="text" class="fade" name="website" value="Current website">
restoreMe 只是用 jquery 将默认值淡化回来
【问题讨论】:
-
你在哪个事件上调用了这个函数?
-
<input onblur="restoreMe(this)" onfocus="clearMeHttp(this)" type="text" class="fade" name="website" value="Current website"> -
我不确定,但您必须为此使用 setselectionrange 函数。
标签: javascript jquery input textinput