js function中返回function 闭包
来源:互联网 发布:windows 返回桌面 编辑:程序博客网 时间:2024/04/19 15:58
<html><script>window.onload = function(){debuggera();b();function a(){for(var i =1;i<4;i++){var p = createElement("a", { href: "javascript:void(0)" }); p.appendChild(createElement("p", null, null, i));//就算onclick事件注册后也会被修改最新的i值p.onclick = function(){console.log(i);}document.getElementById('div').appendChild(p);}}function b(){for(var i =1;i<4;i++){var p1 = createElement("a", { href: "javascript:void(0)" }); p1.appendChild(createElement("p", null, null, i + 3));p1.onclick = function(c){return function(){console.log(c);};}(i + 3)//一开始写成这样 结果返回值一直都是7//p1.onclick = function(){//return function(c){//console.log(c);//}(i + 3);//}document.getElementById('div').appendChild(p1);}}}</script><head></head><body><div id='div'></div></body></html><script>function createElement(tagName, attributes, styles, text) { var v = document.createElement(tagName); if (attributes) { for (var a in attributes) { if (attributes[a]) { if (a == "className") { v.className = attributes[a]; } else { v.setAttribute(a, attributes[a]); } } } } if (styles) { for (var s in styles) { v.style[s] = styles[s]; } } if (text) { v.appendChild(document.createTextNode(text)); } return v;}</script>
阅读全文
0 0
- js function中返回function 闭包
- (function (){})(); JS 闭包
- js中function new function new Function
- (function (){})(); JS 闭包 (Closure) 范式
- js中function()用法
- JS中function()使用方法
- js中 (function(){})()
- js中Function类型
- 解决WebView实现获得js中Function返回值
- js中function与new function
- function?闭包?
- function与闭包
- new function(){}与function(){}() 闭包区别
- js Function function
- js 面向对象学习4 function 和闭包
- js中function参数默认值
- js中function参数默认值
- js中function参数默认值
- Python with
- 算法导论学习-插入排序python实现
- spring mvc + mybatis 连接同一地址的多个数据库
- menuconfig详解(1)——Enable loadable module support
- mybatis动态sql中foreach标签的使用
- js function中返回function 闭包
- servlet与cgi的区别与关系(2)--servlet与tomcat
- Java 性能优化
- arm汇编—bic ,orr
- Android自定义View单TextView显示多种文字样式
- BugKu MISC 部分题目Write_up(二)
- Android端百度地图开发之多个信息窗
- 【蓝桥杯】【字母图形】
- 数学复习(2017NOIP集训)