Javascript JQuery插件在modal中不起作用

Javascript JQuery插件在modal中不起作用,javascript,jquery,css,jquery-plugins,modal-dialog,Javascript,Jquery,Css,Jquery Plugins,Modal Dialog,我很难使用jqmodal让名为ui multiselect的jquery插件正确地显示在模态内部。事实上,我尝试过另一种叫做SimpleMoal的模式,以及另一种不同的multiselect插件,但没有成功。据我所知,似乎没有应用for uimultiselect的CSS,因为multiselect位于modal div中,该div在页面加载时具有display:none。我尝试过其他人提出的许多不同的建议,但都没有奏效。也许我做错了 在我的代码中,我在模式的内部和外部显示了multiselec

我很难使用jqmodal让名为ui multiselect的jquery插件正确地显示在模态内部。事实上,我尝试过另一种叫做SimpleMoal的模式,以及另一种不同的multiselect插件,但没有成功。据我所知,似乎没有应用for uimultiselect的CSS,因为multiselect位于modal div中,该div在页面加载时具有display:none。我尝试过其他人提出的许多不同的建议,但都没有奏效。也许我做错了

在我的代码中,我在模式的内部和外部显示了multiselect。它在外面工作得非常好

这是我的html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>jQuery UI Multiselect</title>
        <link rel="stylesheet" href="css/multiselect/common.css" type="text/css" />
    <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/ui.all.css" />
    <link type="text/css" href="css/multiselect/ui.multiselect.css" rel="stylesheet" />


    <link type="text/css" rel="stylesheet" href="css/jqModalForm.css" />
    <link type="text/css" rel="stylesheet" href="css/main.css" />
    <link type="text/css" rel="stylesheet" href="css/jqModal.css" />


    <script type="text/javascript" src="js/multiselect/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="js/multiselect/jquery-ui-1.8.custom.min.js"></script>

    <script type="text/javascript" src="js/multiselect/plugins/localisation/jquery.localisation-min.js"></script>
    <script type="text/javascript" src="js/multiselect/plugins/scrollTo/jquery.scrollTo-min.js"></script>



    <script type="text/javascript" language="javascript" src="js/jqModal.js"></script>
    <script type="text/javascript" language="javascript" src="js/jqDnR.js"></script>
    <script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>

    <script type="text/javascript" charset="utf-8">
        $().ready(function() {
            $('#addShortCodes').jqm({
                trigger: '#addShortCodesTrigger',
                overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
                overlayClass: 'whiteOverlay'
            })
            .jqDrag('.jqDrag'); /* make dialog draggable, assign handle to title */

            // Close Button Highlighting. IE doesn't support :hover. Surprise?
            $('input.jqmdX')
            .hover(function(){ $(this).addClass('jqmdXFocus'); },function(){ $(this).removeClass('jqmdXFocus'); })
            .focus(function(){ this.hideFocus=true; $(this).addClass('jqmdXFocus'); })
            .blur(function(){ $(this).removeClass('jqmdXFocus'); });

        });
    </script>



</head>
<body>
    <a href="http://github.com/michael/multiselect"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub" /></a>

    <div id="wrapper">

        <div id="content">


            <form action="index.html">
                <select id="countries" class="multiselect" multiple="multiple" name="countries[]">
                    <option value="AFG">Afghanistan</option>
                    <option value="ALB">Albania</option>
                    <option value="FRA">France</option>
                </select>



                <br/>
                <input type="submit" value="Submit Form"/>
            </form>

            <a href="#" id="addShortCodesTrigger">Add</a>
    <script type="text/javascript" src="js/multiselect/ui.multiselect.js"></script>

<script type="text/javascript">
    $(function(){
        $.localise('ui-multiselect', {/*language: 'en',*/ path: 'js/locale/'});
        $(".multiselect").multiselect();
        $('#switcher').themeswitcher();
    });
</script>

            <div id="addShortCodes" class="jqmDialog">
                <div class="jqmdTL">
                    <div class="jqmdTR">
                        <div class="jqmdTC jqDrag">Add Short Codes</div>
                    </div>
                </div>
                <div class="jqmdBL">
                    <div class="jqmdBR">
                        <div class="jqmdBC">
                            <form id="addMonitor" action="addMonitor.do" method="post">
                                <div class="leftBox1">
                                    Short Codes:
                                    <textarea name="shortCodes" cols="20" rows="8"></textarea>

                                </div>
                                <div class="rightBox1">
                                    <select id="countries" class="multiselect" multiple="multiple" name="countries[]">
                                        <option value="AFG">Afghanistan</option>
                                        <option value="ALB">Albania</option>
                                        <option value="FRA">France</option>
                                    </select>



                                </div>
                                <input type="hidden" name="requestId" value="${monitorRequest.requestId}" />
                                <div class="centerBox1">
                                    <input type="submit" value="Add" />
                                </div>
                            </form>

                        </div>
                    </div>
                </div>
                <input type="image" src="dialog/close.gif" class="jqmdX jqmClose" />
            </div>











            <script type="text/javascript"
                    src="http://jqueryui.com/themeroller/themeswitchertool/">
            </script>
            <div id="switcher"></div>

            <h2>Features</h2>
            <ul>
                <li>Search within available options, if there are a lots of them</li>

                <li>Displaying counts of selected and available items</li>
                <li>Select All / Deselect All Buttons</li>
                <li>Dragging items from the available list to the selected list directly</li>
            </ul>

            <h2>Contributors</h2>
            <ul>
                <li><a href="http://github.com/michael/multiselect/">Michael Aufreiter</a></li>

                <li><a href="http://github.com/yanickrochon/multiselect">Yanick Rochon</a></li>
            </ul>
            </p>
            <h2>Misc</h2>
            <p>
                There are no limitations. Do whatever you want with this plugin.
                If you did some nice modifications, just let me know (via Github). I'd be happy to include them.
            </p>

            <h2>Elsewhere</h2>

            <ul>
                <li><a href="http://quasipartikel.at/donut">DONUT? - Radial Navigator</a> <small style="color: red;">NEW!</small></li>
            </ul>
        </div>

        <div id="footer">
            <p class="left">A <a href="http://quasipartikel.at/">Quasipartikel</a> Production</p>

            <p class="right">Template adopted from <a href="http://orderedlist.com/demos/fancy-zoom-jquery/">orderedlist.com</a></p>
            <br class="clear"/>
        </div>
    </div>
    <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
        try {
            var pageTracker = _gat._getTracker("UA-10368067-1");
            pageTracker._trackPageview();
        } catch(err) {}</script>
</body>
</html>

请尝试将jquery代码放在目标选择器之前和之后。。。 所以目标选择器之后的jquery代码可以启动它。 因为jquery需要在操作目标之后进行操作

$document.readyhandler $.readyhandler不建议这样做 $handler 您可能正在使用不推荐使用的语法,请尝试以下操作:

$(document).ready(function() { 
而不是这个

$().ready(function() {

我解决了这个问题。我必须在jqmodal的回调中应用multiselect js

        <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            var myOpen=function(hash){
                hash.w.css('opacity',1).show();
                $(".multiselect").multiselect();
                $.localise('ui-multiselect', {/*language: 'en',*/ path: 'js/locale/'});
            };
            $('#addShortCodes').jqm({
                trigger: '#addShortCodesTrigger',
                overlay: 30, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
                overlayClass: 'whiteOverlay',
                onShow:myOpen
            })


            .jqDrag('.jqDrag'); /* make dialog draggable, assign handle to title */

            // Close Button Highlighting. IE doesn't support :hover. Surprise?
            $('input.jqmdX')
            .hover(function(){ $(this).addClass('jqmdXFocus'); },function(){ $(this).removeClass('jqmdXFocus'); })
            .focus(function(){ this.hideFocus=true; $(this).addClass('jqmdXFocus'); })
            .blur(function(){ $(this).removeClass('jqmdXFocus'); });

        });
    </script>

我不知道你的意思。在什么目标选择器之前和之后放置哪些代码?阅读更新,我的意思是你在jquery中使用的目标选择器,就像addShortCodes id tagsok一样,我将multiselect js向下移动到模式触发器下面。仍然不起作用。请参阅上面更新的代码。还有其他建议吗?