随笔分类 -  JAVASCRIPT

摘要:function readDeviceOrientation() { if (Math.abs(window.orientation) === 90) { // Landscape alert... 阅读全文
posted @ 2015-09-25 08:01 Younger 阅读(961) 评论(0) 推荐(0)
摘要:获取 多选项的value/*获取checkbox的全部选中项使用方法:FUNC_getCheckeds($('tr td').find('input[type=checkbox]'));*/function FUNC_getCheckeds(_target){ var _checkedArr... 阅读全文
posted @ 2014-11-14 11:40 Younger 阅读(236) 评论(0) 推荐(0)
摘要:获取最后一个字符str = "1234567";last = str.replace(/^(.*[n])*.*(.|n)$/g, "$2");console.log(last);-->"7"1~500之间的整数/^([1-4]\d{0,2}|500)$/匹配 ][aa] ][bb]str.match... 阅读全文
posted @ 2014-03-04 15:26 Younger 阅读(205) 评论(1) 推荐(1)
摘要:if () {} else {} ——使用三元操作符/省略大括号{}if(foo){ funcA();}else{ funcB();}foo?funcA():funcB();if(!foo){ funcA();}else{ funcB();}foo?funcB():funcA();if(foo){ return funcA();}else{ return funcB();}return foo?funcA():funcB();if(foo){ return funcA()}else{ funcB()}{if(foo)return funcA();... 阅读全文
posted @ 2013-09-10 17:14 Younger 阅读(3339) 评论(0) 推荐(0)
摘要:实时监听输入框值变化首先创建Jquery.fn扩展jQuery.fn.extend({ inputChange: function(callback){ if($.support.leadingWhitespace){ //if($.browser.msie){ this.bind('propertychange', function(e){ if(e.originalEvent.propertyName == 'value'){ $(this).keyup(); ... 阅读全文
posted @ 2013-08-23 14:25 Younger 阅读(256) 评论(0) 推荐(0)
摘要:function getUrlParm(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"), r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null;}eg:http://www.abc.com/index?parname=1234567console.log(getUrlParm(par 阅读全文
posted @ 2013-08-07 13:18 Younger 阅读(343) 评论(0) 推荐(0)
摘要:高级办法,全局控制遍历实现window.onload=function(){ for(var ii=0; ii<document.links.length; ii++) document.links[ii].onfocus=function(){this.blur()}}将其封装为一个函数function fHideFocus(tName){aTag=document.getElementsByTagName(tName);for(i=0;i<aTag.length;i++)aTag[i].hideFocus=true;//for(i=0;i<aTag.length;i++) 阅读全文
posted @ 2013-04-27 12:26 Younger 阅读(288) 评论(0) 推荐(0)
摘要:var tagData = "varName";$.post(ajaxPostUrl, eval("({" + tagData + ":1})"));//$.post(url,{name:value})//当name为变量时,使用上面的写法//js滚动条到最底端控制document.getElementByIdx ( 'chatboard').scrollTop=document.getElementByIdx ( 'chatboard').scrollHeight ;function loadImag 阅读全文
posted @ 2012-12-11 14:35 Younger 阅读(249) 评论(0) 推荐(0)
摘要:$(function() { $("[class^='TextCut']").each(function() { var cutlength = parseInt($(this).attr('class').replace("TextCut", "")); var text = $(this).html().trim(); $(this).attr("title", text); text = (text.length > cutlength + 2) ? (text.subs 阅读全文
posted @ 2012-10-30 13:50 Younger 阅读(1069) 评论(0) 推荐(0)
摘要:1.丢弃小数部分,保留整数部分php: intval(7/2)js:parseInt(7/2)2.向上取整,有小数就整数部分加1php: ceil(7/2)js: Math.ceil(7/2)3,四舍五入.php: round(7/2)js: Math.round(7/2)4,向下取整php: floor(7/2)js: Math.floor(7/2) 阅读全文
posted @ 2012-04-24 17:45 Younger 阅读(677) 评论(0) 推荐(0)
摘要:(function() { //创建补0函数 function p(s) { return s < 10 ? '0' + s: s; } //创建、格式化时间函数 var younger_time = function(time) { var time = new Date(time); var year = time.getFullYear(); var month = time.getMonth() + 1; var day = time.getDate(); //格式化时间 var str = year + '-' + p(month) + ' 阅读全文
posted @ 2011-07-28 13:55 Younger 阅读(25452) 评论(1) 推荐(2)
摘要:<input type="text" id="eeee"><input type="button" value="点击我看看" onclick="ckChinese(document.getElementById('eeee').value)"> function ckChinese(str){ var reg=/[^\x00-\xff]/g; if (reg.test(str)==true){ alert("含有汉字"); }else 阅读全文
posted @ 2011-02-23 19:07 Younger 阅读(1592) 评论(0) 推荐(0)
摘要:示例 阅读全文
posted @ 2011-01-14 19:00 Younger 阅读(258) 评论(0) 推荐(0)
摘要:[代码]代码 阅读全文
posted @ 2010-12-29 11:53 Younger 阅读(581) 评论(0) 推荐(0)
摘要:为了达到某种特殊的效果我们需要用Javascript动态的去更改某一个标签的Css属性。比如:鼠标经过一个图片时我们让图片加一个边框,代码可能是这样:代码JavaScript CSS Style属性对照表盒子标签和属性对照CSS语法 (不区分大小写)JavaScript语法 (区分大小写)borderborderborder-bottomborderBottomborder-bottom-colorborderBottomColorborder-bottom-styleborderBottomStyleborder-bottom-widthborderBottomWidthborder-col 阅读全文
posted @ 2010-12-29 11:50 Younger 阅读(560) 评论(0) 推荐(0)
摘要:1、直接document.write[代码]2、动态改变已有script的src属性[代码]3、动态创建script元素代码这三种方法都是异步执行的,也就是说,在加载这些脚本的同时,主页面的脚本继续运行,如果用以上的方法,那下面的代码将得不到预期的效果。要动态加载的JS脚本:a.js,以下是该文件的内容。上述代码执行后 a.js 的 alert 执行并弹出消息,但是 主页面产生了错误,没有弹出对话框。原因是 ’str’ 未定义,为什么呢?因为主页面在取 str 的时候 a.js 并没有完全加载成功。遇到需要同步执行脚本的时候,可以用下面的第四种方法。[代码]主页面代码:代码4、原理:用XMLH 阅读全文
posted @ 2010-12-29 11:48 Younger 阅读(952) 评论(0) 推荐(0)
摘要:代码写法二:代码 阅读全文
posted @ 2010-12-29 11:41 Younger 阅读(236) 评论(0) 推荐(0)
摘要:HTML代码如下: 阅读全文
posted @ 2010-12-09 16:39 Younger 阅读(5611) 评论(0) 推荐(0)
摘要:function gtCity(val) { baidu.ajax.post("http://fe.baidu.com/dev/tangram/assets/ajaxRequest.php", "x=" + val, function(xhr, responseText) { if (xhr.status == 200) { if (val == "") {} else { alert("状态" ... 阅读全文
posted @ 2010-12-04 18:47 Younger 阅读(189) 评论(0) 推荐(0)
摘要:function ss(checks){var qx=document.getElementsByName("checkbox");for(var i=0;i 全选 全不选 全选 阅读全文
posted @ 2010-11-26 12:37 Younger 阅读(257) 评论(0) 推荐(0)