html
h11
css
a::before {
content: attr(data-heading);
}
月度归档: 2017年2月
createDOMFromString 用字符串创建dom对象
function createDOMFromString (str){
var objConstain= document.createElement("div");
objConstain.innerHTML=str;
return objConstain;
}
js 原生 select 选中值
var select=document.getElementByTagName("select");
var index=select.selectedIndex;
var text=select.options[index].text;
正则匹配
js url get参数 转码 解码
var target = encodeURI('中文字'); //url转码
var afterConvert = decodeURI('%E7%BE%8E%E5%9B%A2%E7%BD%91'); //结果:"美团网" url解密
thinkphp 跨域
public function _initialize() {
header ( "Content-type:text/html;charset=utf-8" );
header ( "Access-Control-Allow-Origin:*" ); // 允许任何访问(包括ajax跨域)
}
Bootstrap nav hover 导航栏 划过激活
//让 hover 可以触发dropdown
$("#header .nav .dropdown").on("mouseover", function() {
if ($(this).is(".open")) {
return;
}
$(this).find("> a").dropdown("toggle");
})
$("#header .nav .dropdown").on("mouseout", function() {
$(this).removeClass("open");
})
必填选项小插件
声明
需要jq
还需要我的其他小工具
* in_array
调用
function mustFinish_init(){
var mustFinish_list=[
"username",
"password",
]
MF=new mustFinish();
//简易用法
//MF.init("label",mustFinish_list);
//完整用法
MF.labels=$(".clearfix > div > label");
MF.list=mustFinish_list;
MF.init();
}
mustFinish_init();
源码
/*===========================================必填选项*/
function mustFinish(){
var that=this;
this.labels=$("label");//需要标*的地方
this.list=[];//name数组
this.init=function(labels,list){
that.labels=(labels)?$(labels)||that.labels:that.labels;
that.list=list||that.list;
//必填选项标红
that.labels.map(function(index,element){
var namels=$(element).parent().find("[name]");
var isInList=false;
namels.map(function(ind,input){
var namevalue=input.name;
if(in_array(namevalue,that.list)){
isInList=true;
}
})
if(isInList){
var span=createElement("span","","*");
span.style.color="red";
$(element).prepend(span);
}
})
}
this.check=function(){
var isPass=true;
that.list.map(function(ele,ind){
// console.dir($("[name='"+ele+"']"))
var obj=$("[name='"+ele+"']");
var inputValue="";
var Nodename=obj[0].nodeName;
var inputType;
if(Nodename=="SELECT"){inputType="select";}
else{inputType=obj.attr("type");}
switch (inputType) {
case "text":
obj=$(obj[0]);
inputValue=obj.val();
break;
case "password":
obj=$(obj[0]);
inputValue=obj.val();
break;
case "radio":
inputValue=obj.filter(":checked").val();
break;
case "checkbox":
inputValue=obj.filter(":checked").map(function(c_ind,c_ele){return c_ele.value});
break;
case "select":
// console.dir(obj);
var selecter=obj[0];
inputValue=selecter.selectedOptions[0].value;
inputValue=(inputValue=="请选择")?"":inputValue;
break;
default:
obj=$(obj[0]);
inputValue=obj.val();
}
//console.log(inputValue);
if(!inputValue||inputValue==""){
isPass=false;
}
})
return isPass;
}
}
