js----閉パッケージ
4701 ワード
、 ?
, ;
: “ ” 。 , 。
“ ” : “ ”, ( ), 。
, 。 Javascript , 。 :
function a(){
var i=0;
function b(){
alert(++i);
}
return b;
}
var c = a();
c();
:
1、 b a ;
2、 a b。
var c=a() , c b, c() i ( 1)。 , ? a c a b, :
a b a , 。
$(function(){ ---1
var local=1;
window.setInterval(function(){--2
local ++;
window.stats=local;
},3000);
});
1 , 2 , 1
:
...
this.id='someID';
$('*').each(function(){
alert(this.id); // this this this。。。
});
:
this.id='someID';
var outer=this;
$('*').each(function(){
alert(outer.id);
});
:
var k = [];
for (var x = 1; x < 4; x++) {
k.push(function () { return x; });
}
alert(k[0]())
3 , context, k x,
------------------------------------------------------------------------------
, html, 5
1.<html >2.<head>3.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />4.<title> </title>5.<style type="text/css">6.</style>7.<script type="text/javascript">8.9.function init() {
10. var pAry = document.getElementsByTagName("p");
11. for( var i=0; i<pAry.length; i++ ) {
12. pAry[i].onclick = function() {
13. alert(i);
14. }
15. }
16.}
17.</script>18.</head>19.<body onload="init();">20.<p> </p>21.<p> </p>22.<p> </p>23.<p> </p>24.<p> </p>25.</body>26.</html>
,
1、 i (p)
1.2.
3.function init() {
4. var pAry = document.getElementsByTagName("p");
5. for( var i=0; i<pAry.length; i++ ) {
6. pAry[i].i = i;
7. pAry[i].onclick = function() {
8. alert(this.i);
9. }
10. }
11.}
12.
13.14.
2、 i
1.
2.function init2() {
3. var pAry = document.getElementsByTagName("p");
4. for( var i=0; i<pAry.length; i++ ) {
5. (pAry[i].onclick = function() {
6. alert(arguments.callee.i);
7. }).i = i;
8. }
9.
10.}
3
3、 ,i
1.
2.function init3() {
3. var pAry = document.getElementsByTagName("p");
4. for( var i=0; i<pAry.length; i++ ) {
5. (function(arg){
6. pAry[i].onclick = function() {
7. alert(arg);
8. };
9. })(i);// 10. } ----- 。。。
11.}
12.
4、 ,i
1.
2.function init4() {
3. var pAry = document.getElementsByTagName("p");
4. for( var i=0; i<pAry.length; i++ ) {
5. (function () {
6. var temp = i;// 7. pAry[i].onclick = function() {
8. alert(temp);
9. }
10. })();
11. }
12.}
13.
5、 , ( 3 )
1.
2.function init5() {
3. var pAry = document.getElementsByTagName("p");
4. for( var i=0; i<pAry.length; i++ ) {
5. pAry[i].onclick = function(arg) {
6. return function() {// 7. alert(arg);
8. }
9. }(i);
10. }
11.}
12.
6、 Function ,
1.function init6() {
2. var pAry = document.getElementsByTagName("p");
3. for( var i=0; i<pAry.length; i++ ) {
4. pAry[i].onclick = new Function("alert(" + i + ");");//new 5. }
6.}
CSDN , :http://blog.csdn.net/zhouruitao/archive/2008/09/11/2913936.aspx