2013-09-26 65 views
0

嗨我有一個HTML表單,我有一些JavaScript,每次你重點放在輸入欄rel值消失,但它是在所有的輸入類型工作,除了電話,我不知道我做錯了什麼。HTML窗體 - 電話相對值不會消失在焦點

的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')); 
     } 
    }); 

的電話表單字段的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或蘋果瀏覽器。

回答

0

試試這個:

<input type="text" onfocus="if(this.value == '<?= $_POST['field-phone']; ?>') { this.value = ''; }" value="<?= $_POST['field-phone']; ?>" /> 
+0

感謝@brandonjordan工作(: –

+0

很高興幫助快樂編碼! – internetgho5t

1

您使用一個CSS選擇器input[type=phone]是指<input type='phone'/>你沒有。您正在使用<input type='number'/>,因此您需要使用CSS選擇器input[type='number']

+0

即使我改變它輸入[type ='數字']它沒有工作,我知道。 –