简体   繁体   English

重复功能不起作用

[英]Repeat function not working

Right now I have multiple dialog boxes, and have written the following so that the right button opens up the right dialog box. 现在,我有多个对话框,并编写了以下内容,以便右键单击可以打开右侧的对话框。

$(function() {
var i = 0;
if (i < 50) {
    i++;
        $( ".dialog" + i ).dialog({
            autoOpen: false,
            width: 900,
            show: {
            effect: "fade",
            duration: 500
        },
        hide: {
            effect: "fade",
            duration: 500
        }
        });
        $( ".opener" + i ).click(function() {
            $( ".dialog" + i ).dialog( "open" );
        });
    }
});

However, nothing happens now when I click on the buttons. 但是,当我单击按钮时,什么也没有发生。 What am I missing here? 我在这里想念什么?

use while(){} instead of if(){} 使用while(){}代替if(){}

$(function() {
    var i = 0;
    while (i < 50) {
        i++;
            $( ".dialog" + i ).dialog({
                autoOpen: false,
                width: 900,
                show: {
                effect: "fade",
                duration: 500
            },
            hide: {
                effect: "fade",
                duration: 500
            }
            });
            $( ".opener" + i ).click(function() {
                $( ".dialog" + i ).dialog( "open" );
            });
        }
});

Wrote a simpler solution for this just to demonstrate the right technique. 为此,编写了一个更简单的解决方案,以演示正确的技术。
HTML: HTML:

<ul>
    <li class="open" data-modalID="1">open 1</li>
    <li class="open" data-modalID="2">open 2</li>
</ul>

<ul>
    <li class="modal modal_1">Hi, I'm modal 1</li>
    <li class="modal modal_2">Hi, I'm modal 2</li>
</ul>

CSS: CSS:

.modal { display: none; }

jQuery: jQuery的:

(function() {
    $('.open').on('click', function() {
        var modalID =  $(this).attr('data-modalID');

        $('.modal_' + modalID).show();
    });
})();

See http://jsfiddle.net/YAkpq/ 参见http://jsfiddle.net/YAkpq/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM