javascript另类写法】的更多相关文章

今天来介绍一下javascript不一样的写法,很简单哦. 1.当条件成立时执行a方法,当条件失败是执行b方法 通常我们会这样写: var result; if(isOk){ result=funA(); }else{ result=funB(); } 还可以这样表达: var result=isOk? funA():funB() 2.当条件成立执某个方法 通常方式: if(isOk){ doSomething(); } 我更喜欢这样写: isOk&&doSomething(); 如果一个…
原文:JavaScript技巧&写法 JavaScript技巧篇: 1>状态机 var state = function () { this.count = 0; this.fun = null; this.nowcount = 0; }; state.prototype = { load: function (count,fun) { this.count = count; this.fun = fun; this.nowcount=0; }, trigger: function () {…
javascript json写法 var shuxing = {name:"super",sex:"19",work:"IT"}; 这个key不加引号和加引号都可以  主意 key和value不要用单引号…
获取整颗树的另类写法.非递归 //获取所有的菜单 List<T_Menu> menu = bll.getMenuByUsesrID("8189a7c1-6f15-4744-b6c4-d3ee5b5b994d"); //创建EasyTree控件model List<EasyTreeModel> list = new List<EasyTreeModel>(); //把所有菜单添加到list集合中 menu.ForEach(o => { EasyT…
一.什么是对象? 对象是n个属性和方法组成的集合,如js内置的document, Date, Regexp, Math等等 document就是有很多的属性和方法, 如:getElementById, getElementsByTagName等等这些就是document对象支持的方法,那么我们常见的onclick, onmouseover,onmouseout等等就是document支持的属性 二.javascript创建自定义对象,常用的有两种方式: 上面是js内置的对象,如果我们需要自己常见…
addEventListener 参数如下 addEventListener(type, listener[, useCapture]); type,事件名称 listener,事件处理器 useCapture,是否捕获 一直把 listener 记成是响应函数,function 类型.相信很多人也是这么理解的.多数时候是这么使用 elem.addEventListener('click', function(ev) { // todo }, false); 第一个参数没什么异议,第二个参数传一…
简单描述:今天看老大提交的代码,发现了一个有意思的事情,一条sql中判断条件是空,老大的写法,让我眼前一亮.直接上代码 代码: <select id="getxxxs" resultMap="xxxResultMap" parameterType="String"> select <include refid="Field" />from <include refid="tableNam…
看到style,不少人可能会说这个我知道,就是控件写属性的话可以通过style来实现代码的复用,单独把这些属性及其参数写成style就可以便捷的调用. <?xml version="1.0" encoding="utf-8"?><resources> <style name="CustomText" parent="@style/Text"> <item name="andr…
<script type="text/javascript"> function refreshVerify(){ var imgId = document.getElementById("getVerify"); imgId.src = "getVerify.php?ran=" + Math.random(); } </script> ================================ <a href…
1.普通函数定义的两种写法 function hello(){ console.log("hello!"); } var hello = function(){ console.log("hello!"); } 2.函数自执行,快速初始化变量(两种写法hello变量值为15) #函数自执行 var hello = function(num){ return 3 * num; }(5); #普通写法 var hello = 5; hello = 3 * hello;…