jquery只打开第一个按钮

jquery open only first button

本文关键字:第一个 按钮 jquery      更新时间:2023-09-26

这是我打开弹出窗口的代码,类名就像我的输入值。它适用于我在html中的第一部分(PASS是我在html ocde中的第一个),但不适用于其他部分。问题出在哪里?

                </div>
            </div>  
<!---------------- POLL BUTTON DIV(POP-UP)---------------------->
            <div id="modal"  class="poll">
                <div id="content">
                </div>
            </div>  
<!---------------- PASS BUTTON DIV(POP-UP)---------------------->
            <div id="modal"  class="pass">
                <div id="content">
                </div>
            </div>  
    <script type="text/javascript">
        $(document).ready(function() {
            $('#link').click(function(e) { // Button which will activate our modal
            var block = $(this +":input").val();
                $('.'+block).reveal({ // The item which will be opened with reveal
                    animation: 'fade',                   // fade, fadeAndPop, none
                    animationspeed: 600,                       // how fast animtions are
                    closeonbackgroundclick: true,              // if you click background will modal close?
                    dismissmodalclass: 'close'    // the class of a button or element that will close an open modal
                });
            return false;
            });
        });
    </script>

在这些属性上切换classid属性,然后调用jQuery中的类,而不是ID。

在遍历DOM时,ID将只被引用一次。之后它停止搜索。

以下是使用HTML构建结构的正确方法:

        <div id="poll"  class="modal">
            <div class="content">
            </div>
        </div>  
        <div id="pass"  class="modal">
            <div class="content">
            </div>
        </div>  

还将您的<div id="content">更改为<div class="content">,因为您有多个。要特别选择一个,请使用:

$('#pass').find('.content')

作为一个例子。

以下是您将在jQuery中调用的内容:

$('.modal').click()

这将取代您的$('#link').click()