随笔分类 - javascript
摘要:window.event只能在IE下运行,不能在firefox下运行,这是因为firefox的event只能在事件发生的现场使用。 在firefox里直接调用event对象会报undefined。兼容解决方式: *firefox需要传递event对象,书写必须为event
阅读全文
摘要:如果我们不想用 submit 按钮来提交表单,我们也可以用超链接来提交,我们可以这样写代码:Submit Me
阅读全文
posted @ 2014-09-02 11:33
静心聆听
摘要:<a href="#" onClick="parent.iframe名字.focus();window.print();">打印</a>
阅读全文
posted @ 2014-07-14 11:20
静心聆听
摘要:usercenter/index" id="message">
阅读全文
摘要:Javascript代码document.onkeydown=function mykeyDown(){ if(event.keyCode == 13) {checkData();} return; } 以上js代码在IE中运行正常,在Firefox中老报"event is not defined”错误!原因是因为在Firefox中使用了不同的事件对象模型,不同于IE Dom,用的是W3C Dom。Firefox DOM中并无event,采用以下方法解决,同时兼容IE和Firefox。Javascript代码document.onkeydown=fu...
阅读全文
摘要:Favorites //通用加入收藏,设为主页代码functionSetHome(){ if(document.all){ document.body.style.behavior ='url(#default#homepage)'; document.body.setHomePage(window.location.href); }elseif(window.sidebar){ if(window.netscape){ try{ netscape.security.PrivilegeMa...
阅读全文
摘要:if(isNaN(value)){ 不是数字}else{ 全是数字}
阅读全文
摘要:$(function(){ $("#form1").click(function({ document.form_name.action="usercenter/change_username"; document.form_name.submit(); }))})注:如何document.form_name.submit()提示is not function是错误,需要检查一下form表单里是否有name为submit的元素。
阅读全文
摘要:function getRootPath(){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1); return(prePath+postPath);}
阅读全文
摘要:push() 将新元素添加到一个数组中,并返回数组的新长度值。arrayObj.push([item1 [item2 [. . . [itemN ]]]]) 参数 arrayObj 必选项。一个 Array 对象。 item, item2,. . . itemN 可选项。该 Array 的新元素。 说明 push 方法将以新元素出现的顺序添加这些元素。如果参数之一为数组,那么该数组将作为单个元素添加到数组中。如果要合并两个或多个数组中的元素,请使用 concat 方法。 <script> ...
阅读全文
摘要:条件:多选checkbox,将选中的value通过异步传递到处理页面 首选需要一个小函数 示例: 处理页面:
阅读全文
摘要:onload是一个事件属性,该事件会在页面或图像加载完成后立即发生。比如<body onload="一个js函数"> ,那就会在加载完整个页面后触发此事件。也可以直接window.onload=function(){ //代码}来调用
阅读全文
摘要:不要直接这样判断if(!a){ //如果没有定义。。。。}上述方法不可取,js读取一个没有定义的变量会报错,可以更换为if(!window.a){ //如果没有定义}因为window对象是整个dom的对象,表示window的某个属性是否存在,这种方法也是适用全局变量,如果是函数体内的话就要使用typeof()了if(typeof (a) == "undefined"){ //相关操作 }
阅读全文
摘要:一、head区的script会优先于body区的script执行Copy code<html><head><title> 实例:Head区script代先于body区的script执行 </title><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta name="author" content="枫岩,CNLEI" /><meta name
阅读全文
摘要:<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}#l-map{height:100%;width:78%;float:left;border-ri
阅读全文