文本框值在发布时不改变


Textbox value not changing on posting

我以以下方式创建了一个文本框

<input type="text"  name="email" id="email" class="text_inp2" value="Email" onclick="if(this.value=='Email'){this.value='';}" onblur="if(this.value==''){this.value='Email';}" />

所以,它显示默认文本在文本框作为Email,当我编辑它像admin@stackoverflow.com,当我提交(即PHP Post函数)它仍然张贴的值为Email,但不是admin@stackoverflow.com我不想使用查询字符串方法。无论如何,我可以摆脱它通过使用简单的PHP Post函数

您可能需要查看一下输入placeholder属性,并在较旧的浏览器中包含类似http://widgetulous.com/placeholderjs/的内容。

<input type="text" name="email" id="email" placeholder="Email">

有你想要的效果

您可以使用:

onchange="
if(this.value === this.defaultValue){
    this.value = '';
}
else if (this.value === '') {
    this.value = this.defaultValue;
}"

或者为那些讨厌的旧浏览器使用占位符属性…

我在我正在做的一个项目中发现了这个,不确定它是否有效,但如果你有现代化器,你可以尝试一下

if(!Modernizr.input.placeholder){
    $('[placeholder]').focus(function(){
        if($(this).val() === $(this).prop('placeholder')){
            $(this).val('');
            $(this).removeClass('placeholder');
        }
    }).blur(function(){
        if($(this).val() === '' || $(this).val() === $(this).prop('placeholder')){
            $(this).addClass('placeholder');
            $(this).val($(this).prop('placeholder'));
        }
    }).blur();
    $('[placeholder]').parents('form').submit(function(){
        $(this).find('[placeholder]').each(function(){
            if($(this).val() === $(this).prop('placeholder')){
                $(this).val('');
            }
        });
    });
}