function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++){
temp += splitstring[i];
}
return temp;
}
分类: 前端
js lpad
function lpad(len,initstr,padstr)
{
var result="";
for(var i=1;i<=len-initstr.toString().length;i++)
{
result += padstr;
}
result += initstr;
return result;
}
开始在固定位置 达到一定高度后随屏幕滚动
<style type="text/css">
.div1 {
height:2000px;
}
.div2 {
width:200px;
height:200px;
background-color:#3399FF;
margin-top:100px;
}
.div2_1{
position:fixed;
width:200px;
height:200px;
z-index:999;
background-color:#3399FF;
top:0px;
_position:absolute;
_bottom:auto;
_top:[removed]eval(document.documentElement.scrollTop));
}
</style>
<script type="text/javascript">
window.onscroll=function(){
var t=document.documentElement.scrollTop||document.body.scrollTop;
var div2=document.getElementById("div2");
if(t>= 100){
div2.className = "div2_1";
}else{
div2.className = "div2";
}
}
</script>
<div class="div1">
<div id="div2" class="div2"></div>
</div>
在内部使用js的function
项目中有个地方需要用到js的一个function
而且必须要在jquery的$()内用这个function
所以就用到了attr 把标签内的onclick拿出来
在外层用eval()包裹 这样把需要执行的function 放在$()内
然就eval包裹后就可以直接用了
jquery 移除input file 内容
var file = $("#AidImg");
file.after(file.clone().val(""));
file.remove();
百度地图api的覆盖物样式与bootstrap样式表冲突
#map_canvas img,
.google-maps img {
max-width: none;
}
在使用百度地图时,将展现地图的div的id换成map_canvas即可
JS 中如何判断 undefined 和 null
JS 中如何判断 undefined
以下是不正确的用法:
exp 为 null 时,也会得到与 undefined 相同的结果,虽然 null 和 undefined 不一样。注意:要同时判断 undefined 和 null 时可使用本法。
var exp = undefined;
if (typeof(exp) == undefined)
{
alert("undefined");
}
——————————————————————————–
JS 中如何判断 null
exp 为 undefined 时,也会得到与 null 相同的结果,虽然 null 和 undefined 不一样。注意:要同时判断 null 和 undefined 时可使用本法。
var exp = null;
if (!exp)
{
alert("is null");
}
为了向下兼容,exp 为 null 时,typeof 总返回 object。
JavaScript 中没有 isNull 这个函数。
<p 10px auto; color: rgb(0, 0, 0); font-family: Verdana, 'Lucida Grande', Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; widows: 1;">尽管如此,我们在 DOM 应用中,一般只需要用 (!exp) 来判断就可以了,因为 DOM 应用中,可能返回 null,可能返回 undefined,如果具体判断 null 还是 undefined 会使程序过于复杂。
Jquery 过滤空格
$.trim(str) 返回:string; 说明:去掉字符串首尾空格。
JS 字符串时间格式化
new Date($("#start_date").val()).Format("yyyy-MM-dd");
form submit 验证
<script>
function submitFun(){
//逻辑判断
return true; //允许表单提交
//逻辑判断
return false;//不允许表单提交
}
</script>
<form onsubmit="reture submitFun();"> //注意此处不能写成 onsubmit="submitFun();"否则将表单总是提交
</form>