Javascript学习:综合案例3--循环里面套点击事件

版权声明:谁没个菜的时候! https://blog.csdn.net/qq_32584661/article/details/80690275

js自学网站推荐:http://www.51zxw.net/study.asp?vip=4857021

方法一:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <input type="button" value="button1" id="button1">
    <input type="button" value="button2" id="button2">
    <input type="button" value="button3" id="button3">
    <input type="button" value="button4" id="button4">


    <script>

        function coloript() {

            var colorarr=["green","red","blue","orange"];
            var divarr=document.getElementsByTagName("input");

            for(var i=0;i<divarr.length;i++){

                (function (x) {
                    divarr[x].onclick=function () {
                        alert(colorarr[x]);
                    }
                })(i);  //匿名函数自执行传参

            };

        };

        coloript();


    </script>

</body>
</html>

方法二:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <input type="button" value="button1" id="button1">
    <input type="button" value="button2" id="button2">
    <input type="button" value="button3" id="button3">
    <input type="button" value="button4" id="button4">


    <script>

        function coloript2() {

            var colorarr=["green","red","blue","orange"];
            var divarr=document.getElementsByTagName("input");

            for(var i=0;i<divarr.length;i++){

                (function () {
                    var c=i;
                    divarr[i].onclick=function () {
                        alert(colorarr[c]);
                    }
                })();

            };

        };

        coloript2();


    </script>

</body>
</html>

是不是游标里面不能欠套循环.......

10-13

declare @dhnum intrndeclare @begin intrndeclare @end intrndeclare @iid intrndeclare @content varchar(1000)------------足够大rndeclare @otherlist varchar(10)rndeclare @a intrnrndeclare MyCursor CURSOR FORrnrnselect iid,otherlist,content from tablelist order by iidrnopen MyCursorrnFETCH NEXT FROM MyCursor INTO @iid,@otherlist,@contentrn--set @content=''rnwhile @@FETCH_STATUS = 0rnbeginrn set @iid=1rn set @begin=1rn if @content not like '%,%'rn beginrn insert into tablelistOK(otherlist,contentALL)VALUES(@otherlist,@content)rn end rn ELSErn BEGINrn select @dhnum=len(@content)-len(replace(@content,',',''))rn set @a=1rn while @a<=@dhnumrn beginrn insert into tablelistOK(otherlist,contentALL)VALUES(@otherlist,substring(@content,1,charindex(',',@content)-1))rn update tablelist set content=substring(@content,charindex(',',@content)+1,len(@content)-charindex(',',@content)) where iid=@iidrn set @a=@a+1rn endrn ENDrn FETCH NEXT FROM MyCursor INTO @iid,@otherlist,@contentrnendrnCLOSE MyCursorrnDEALLOCATE MyCursor rnrn执行后插入到表tablelistOK中的都是第一个逗号前面的,难道游标里面不可以嵌套循环还是其他的地方错了?rn结果是这样的rn 1 lilaoshi ddfdrn 2 lilaoshi ddfdrn 3 zhangyh 111rn 4 zhangyh 111rn 5 zhangyh 111rn 6 hongh sdfrn 7 hongh sdfrn 8 hongh sdfrn 9 yuey 999rn 10 yueyue 789rnrn可是表tablelist 中是rn 1 lilaoshi ddfd,grttrn 2 zhangyh 111,222,333,rn 3 hongh sdf,yjhyt,gferg,346,gjhgjrn 4 yuey 999,rn 5 yueyue 789rn我想分开把表tablelist 弄成rn 1 lilaoshi ddfdrn 2 lilaoshi grttrn 3 zhangyh 111rn 4 zhangyh 222rn 5 zhangyh 333rn 6 hongh sdfrn 7 hongh yjhytrn 8 hongh gfergrn 9 hongh 346rn 10 hongh gjhgjrn 11 yuey 999rn 12 yueyue 789rn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试