javascript - 如何在输入文本字段中使占位符闪烁到 focusout

标签 javascript jquery css html user-interface

我想在聚焦时使占位符文本闪烁。

这是我的 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

现在我想闪烁占位符文本“请单击此处进行 key 卡扫描工作”。

所以请有人能帮帮我吗???

最佳答案

这里是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">

关于javascript - 如何在输入文本字段中使占位符闪烁到 focusout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28472901/

相关文章:

javascript - 如何根据另一个对象数组的键形成一个对象?

javascript - 您可以使用 Service Worker 在网络蓝牙中运行后台 iBeacon/Eddystone 扫描吗?

javascript - for循环中的点击事件

javascript - jQuery.is() :first showing different behavior from :last

javascript - 如何解决这个 javascript switch 语句问题,switch 语句不起作用

PHP CSS 从字符串到数组

javascript - Function.name 属性有多有用?

javascript - 在遵守 W3C 规则的同时在 JavaScript 字符串中使用 HTML 标签

html - Internet Explorer 中的负边距

html - 如何让背景图片覆盖整个页面