2015-02-12 49 views
1

我想讓注視時佔位符文本閃爍。如何在輸入文本框中聚焦注意佔位符

這是我的html代碼:

<input type="text" id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder=" Please click here to Key Fob scanning work"> 

這是我的jQuery代碼:

$('#keyfob').on("focus blur", function(){ 
    $(this).attr("placeholder") == "" ? $(this).attr("placeholder", "Please click here for Key Fob scanning to work") : $(this).attr("placeholder", ""); 
}); 

working js fiddle code

現在我想閃爍佔位符文本「請點擊這裏鑰匙鏈掃描工作「。

那麼請任何人都可以幫我嗎?

回答

0

這裏是jQuery的

function blink() { 

if ($('input[type=text]').attr('placeholder')) { 
// get the placeholder text 
$('input[type=text]').attr('placeholder', ''); 
} 
else { 
    $('input[type=text]').attr('placeholder', 'Placeholder Text...'); 
} 
setTimeout(blink, 1000); 
} 

HTML

<body onload='blink()'> 
<input type="text" on-click='blink()' id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder=" Please click here to Key Fob scanning work"> 
+0

u能送我的工作它JS小提琴,這裏不閃爍,我 – Bhairav 2015-02-12 08:57:41

+0

兄弟是workig .. [http://plnkr.co/edit/XLn9oW5tDSLaDpc4e2W4?p=preview] – Rkn 2015-02-12 09:28:29

+0

嘿嘿的onfocus也是它的閃爍兄弟..我想眨眼它只在聚焦Bro – Bhairav 2015-02-12 09:47:42

0

您正在尋找這樣的事情:

<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     var clicked; 
     $('#keyfob').focusout(function() { 
      var s = $('#keyfob').attr("placeholder"); 
      clicked=true; 
      blinking();  
     }); 
     $('#keyfob').click(function() { 
      clicked=false; 
      $('#keyfob').attr("placeholder", ''); 
     }); 
     function blinking() { 
       if(clicked){ 
        $('#keyfob').attr("placeholder", ''); 
       setTimeout(function() { 
        $('#keyfob').attr("placeholder", 'Please click here to Key Fob scanning work'); 
        setTimeout(blinking, 500); 
       }, 1000); 
      } 
     } 
     }); 
    </script> 

    </head> 

    <body> 
     <input type="text" id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder="Please click here to Key Fob scanning work"> 
    </body> 
</html> 
+0

thanxs作出迴應。你可以爲上面的代碼創建一個jsfiddle,因爲它不適合我 – Bhairav 2015-02-12 11:13:17

+0

http://jsfiddle.net/tj9o49tk/,它適用於聚焦 – Dileep 2015-02-12 11:15:55

+0

仍然光標和佔位符都閃爍@dileep我不想眨眼他們兩個 – Bhairav 2015-02-12 11:16:51

0

看到這個thread,顯示如何將其與普通的CSS只是來完成,沒有任何JavaScript/jQuery。

@Pinal特別感謝他幫助我使它在Firefox上工作。

相關問題