首页 > 代码库 > javascrip for 循环数组事件绑定

javascrip for 循环数组事件绑定

//radio选择填充,字段
    var radioArray = ["F_RegisterCode", "F_Subjection", "F_MechanismType"]
    for (v in radioArray) {
        (function(F) {
            $(‘:radio[name="‘ +F + ‘"]‘).change(function () {
                var str = $(this).val();
                $(‘.‘ + F).each(function (i) {
                    console.log(radioArray[v]);
                    $(this).val(str[i]);
                })
            })
        })(radioArray[v])
    }
<script type="text/javascript">
    $(function() {
        var li = $(‘.se-btn li‘);
        var pattern = ‘images/ser‘;

        for (var i = 0; i < 9; i++) {
            (function(i) {
                var url = li.eq(i).find(‘span‘).css(‘background-image‘);
                var length = url.split(‘‘).length;          //获取url的长度
                var ind1 = url.search(pattern);             //返回字符串中 pattern开始位置
                var qian = url.slice(0, ind1 + 10);         //前面的字符串
                var hou = url.slice(ind1 + 10);             //后面的字符串

                li.eq(i).hover(function() {
                    $(this).find(‘span‘).css({
                        ‘background-image‘: qian + ‘h‘ + hou //中间加个 ‘h‘
                    });
                }, function() {
                    $(this).find(‘span‘).css({
                        ‘background-image‘: qian + hou
                    });
                });
            })(i);
        }

    });
    </script>

javascrip for 循环数组事件绑定