0

嗨,我有一个 html 表单,我有一些 javascript,每次您关注输入字段时,rel 值都会消失,但是它适用于除电话以外的所有输入类型,我不确定我做错了什么。

javascript是:

$(document).ready(function() {

    $('select.fancyselect').fancySelect();

    $('input[type=text], input[type=email], input[type=phone], input[type=url], textarea,').focus(function(){ 
        if($(this).val() == $(this).attr('rel')) {
            $(this).val('');
        }
    });

    $('input[type=text], input[type=email], input[type=phone], input[type=url], textarea').blur(function(){
        if($(this).val() == '') {
            $(this).val($(this).attr('rel'));
        } 
    });

tel 表单字段的 html 是:

<div class="control-group">
                                <label class="control-label" for="field-phone">Phone Number:<br /> <em>(Optional)</em></label>
                            <div class="controls">
                                <input type="number" name="field-phone" id="field-phone" value="<?= $_POST['field-phone']; ?>" rel="Phone number here...">
                            </div>
                          </div>

我也在使用引导程序,我发现这个问题只发生在 Firefox 中,而不是 chrome 或 safari。

4

2 回答 2

1

您正在使用一个 CSS 选择器input[type=phone],它指的是<input type='phone'/>您没有的。您正在使用<input type='number'/>,因此您需要使用 CSS 选择器input[type='number']

于 2013-09-26T11:55:59.203 回答
0

尝试这个:

<input type="text" onfocus="if(this.value == '<?= $_POST['field-phone']; ?>') { this.value = ''; }" value="<?= $_POST['field-phone']; ?>" />
于 2013-09-26T11:55:16.753 回答