web前端|js教程
placeholder,html5
web前端-js教程
html5原生支持placeholder,对于不支持的浏览器(ie),可用js模拟实现。
js代码
时时彩合买平台源码,ubuntu cd/dvd,tomcat8 配置部署,怎么暂停爬虫,php 企业信息管理系统,辽宁正规抖音seo优化销售电话lzw
(function(){
//判断是否支持placeholder
function isPlaceholer(){
var input = document.createElement(input);
return "placeholder" in input;
}
//不支持的代码
if(!isPlaceholer()){
//创建一个类
function Placeholder(obj){
this.input = obj;
this.label = document.createElement(label);
this.label.innerHTML = obj.getAttribute(placeholder);
this.label.style.cssText = position:absolute; text-indent:4px;color:#999999; font-size:12px;;
if(obj.value != \){
this.label.style.display = one;
}
this.init();
}
Placeholder.prototype = {
//取位置
getxy : function(obj){
var left, top;
if(document.documentElement.getBoundingClientRect){
var html = document.documentElement,
body = document.body,
pos = obj.getBoundingClientRect(),
st = html.scrollTop || body.scrollTop,
sl = html.scrollLeft || body.scrollLeft,
ct = html.clientTop || body.clientTop,
cl = html.clientLeft || body.clientLeft;
left = pos.left + sl - cl;
top = pos.top + st - ct;
}
else{
while(obj){
left += obj.offsetLeft;
top += obj.offsetTop;
obj = obj.offsetParent;
}
}
return{
left: left,
top : top
}
},
//取宽高
getwh : function(obj){
return {
w : obj.offsetWidth,
h : obj.offsetHeight
}
},
//添加宽高值方法
setStyles : function(obj,styles){
for(var p in styles){
obj.style[p] = styles[p]+px;
}
},
init : function(){
var label = this.label,
input = this.input,
xy = this.getxy(input),
wh = this.getwh(input);
this.setStyles(label, {width:wh.w, height:wh.h, lineHeight:20, left:xy.left, op:xy.top});
document.body.appendChild(label);
label.onclick = function(){
this.style.display = "none";
input.focus();
}
input.onfocus = function(){
label.style.display = "none";
};
input.onblur = function(){
if(this.value == ""){
label.style.display = "block";
}
};
}
}
var inpColl = document.getElementsByTagName(input),
textColl = document.getElementsByTagName( extarea);
//html集合转化为数组
function toArray(coll){
for(var i = 0, a = [], len = coll.length; i < len; i++){
a[i] = coll[i];
}
return a;
}
var inpArr = toArray(inpColl),
textArr = toArray(textColl),
placeholderArr = inpArr.concat(textArr);
for (var i = 0; i < placeholderArr.length; i++){
if (placeholderArr[i].getAttribute(placeholder)){
new Placeholder(placeholderArr[i]);
}
}
}
})()
html代码:
淘金币领取源码,vscode换中文模式,预装ubuntu,tomcat服务器上传,sqlite数据库自定义函数,音乐网页设计模板,mysql实例数据库,四川绵阳服务器,jquery筛选过滤插件,支付宝app 混合前端框架,橡皮爬虫,php jwt,百合seo,springboot分环境,帝国文章页分页标签,获取网站访客qq 源码,手机网页视频播放软件有哪些,asp cms模板制作,cms后台密码忘记,执行js后页面滚动失效,bs图书管理系统,酷刷平台源码程序lzw
css代码:
防qq截图c 源码,ubuntu显卡驱动卡住,tomcat8.0压缩包,python 最好爬虫库,广州贤人汇国际php面试,seo軟件lzw
div,input,textarea{ margin:0; padding:0;}
div{width:400px; margin:100px auto 0;}
input,textarea{width:200px;height:20px; margin-top:5px;line-height:20px;border:1px #666666 solid; background-color:#fff; padding-left:2px;}
textarea{ height:60px; font-size:12px; resize:none;}