IE下实现placeholder效果的jquery插件

$(document)
		.ready(
				function() {
					var doc = document, inputs = doc
							.getElementsByTagName('input'), supportPlaceholder = 'placeholder' in doc
							.createElement('input'), placeholder = function(
							input) {
						var text = input.getAttribute('placeholder'), defaultValue = input.defaultValue;
						if (defaultValue == '') {
							input.value = text
							input.setAttribute("old_color", input.style.color);
							input.style.color = "#c0c0c0";
						}
						input.onfocus = function() {
							this.style.color = this.getAttribute("old_color");
							if (input.value === text) {
								this.value = ''
							}
						};
						input.onblur = function() {
							if (input.value === '') {
								this.style.color = "#c0c0c0";
								this.value = text
							}
						}
					};
					if (!supportPlaceholder) {
						for ( var i = 0, len = inputs.length; i < len; i++) {
							var input = inputs[i], text = input
									.getAttribute('placeholder');
							if (input.type === 'text' && text) {
								placeholder(input)
							}
						}
					}
				});
直接把代码复制下来,保存成一个js文件引用即可,根本不用再做任何处理,超级方便~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实现搜索栏placeholder滚动播放效果,可以使用CSS3动画和JavaScript实现。 首先,使用CSS3动画来实现placeholder的滚动效果,可以使用以下代码: ```css .search-input { animation: placeholder 10s linear infinite; } @keyframes placeholder { 0% { opacity: 1; } 20% { opacity: 0; } 40% { content: "Search for..."; opacity: 1; } 60% { content: "Find what you need..."; opacity: 1; } 80% { content: "Explore your interests..."; opacity: 1; } 100% { content: "Try me now..."; opacity: 1; } } ``` 上述代码中,使用了`animation`属性来定义动画效果,`placeholder`是动画名称,`10s`表示动画持续时间为10秒,`linear`表示动画速度为匀速,`infinite`表示动画无限循环。 接下来,使用JavaScript来实现placeholder的动态替换,可以使用以下代码: ```javascript const placeholder = document.querySelector('.search-input').getAttribute('placeholder'); const phrases = ['Search for...', 'Find what you need...', 'Explore your interests...', 'Try me now...']; let i = 0; setInterval(() => { document.querySelector('.search-input').setAttribute('placeholder', phrases[i]); i = (i + 1) % phrases.length; }, 10000); ``` 上述代码中,使用`setInterval`函数来定时替换placeholder内容,`10000`表示每隔10秒替换一次。在替换时,将`phrases`数组中的内容依次赋值给placeholder,使用取余的方式实现数组循环。 以上就是实现搜索栏placeholder滚动播放效果的方法,希望能对你有所帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值