0

在我的 php 页面中,我有一个 jquery 脚本来打开一个对话窗口。代码如下

<script type="text/javascript">
            $(document).ready(function() {
                var $loading = $('<img src="loading.gif" alt="loading" class="loading">');

                $('#data-specs a').each(function() {
                    var $dialog = $('<div></div>')
                        .append($loading.clone());

                    var $link = $(this).one('click', function() {
                        $dialog

                            .load($link.attr('href'))
                            .dialog({
                                title: '<?php echo $_GET["indQ"];?>',
                                modal: true,
                                width: 500,
                                height: 300,
                                minHeight: 300,
                                maxHeight: 600,
                                minWidth: 500,
                                maxWidth: 800
                                });

                            $link.click(function() {
                            $dialog.dialog('open');

                            return false;
                        });

                        return false;
                    });
                });

                $('#dav').val(getURLParameter('davQ'));

                $('#pathogen').val(getURLParameter('pathogenQ'));

                $('#topicF').val(getURLParameter('topicQ'));

                $('#ind').val(getURLParameter('indQ'));

                $('#subind').val(getURLParameter('subindQ'));

                $(".selfont").change(function (event) {
                        window.location = '?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val() + '&indQ=' + encodeURIComponent($('#ind').val()) + '&subindQ=' + encodeURIComponent($('#subind').val());
                });

                function getURLParameter(name) {
                         return decodeURIComponent((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]);
                }

            });
    </script>

数据位于 id='data-specs' 的表中。而且效果很好。最近我添加了一个带有值的下拉框,以使用 ajax 脚本对该表进行排序,它也可以工作。但问题是在这个 ajax 调用之后,当我单击链接以打开对话框窗口时,它会在父窗口本身中打开,如果我们按下浏览器后退按钮然后单击链接,它将打开没有错误的对话框窗口!即使在使用 ajax 完成排序后,我如何才能做到这一点?请给我一些解决方案。我要排序的ajax代码如下所示

function ajaxFunction(){

    //to keep selection in countryList - GP
    var ref = document.getElementById('countryRF');
    for(i=0; i<ref.options.length; i++)
    ref.options[i].selected = true;


    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            //document.myForm.time.value = ajaxRequest.responseText;
            document.getElementById("result").innerHTML=ajaxRequest.responseText

        }
    }

    var dav = document.getElementById('dav').value;
    var pathogen = document.getElementById('pathogen').value;
    var topicF = document.getElementById('topicF').value;
    var ind = document.getElementById('ind').value;
    var subind = document.getElementById('subind').value;
    var selObj = document.getElementById('countryRF');
    var cnty = loopSelected(selObj).join('~');  // join array into a string
    var sortby = document.getElementById('sortby').value;

    var queryString = "?dav=" + dav + "&pathogen=" + pathogen + "&topicF=" + topicF + "&ind=" + encodeURIComponent(ind) + "&subind=" + encodeURIComponent(subind) + "&cnty=" + encodeURIComponent(cnty) + "&sortby=" + sortby;
    ajaxRequest.open("GET", "sortbyD.php" + queryString, true);
    ajaxRequest.send(null);
    return false;
}

请帮我解决这个问题..

4

1 回答 1

1

第一次加载页面时,对话框事件与元素绑定,在 ajax 之后,您需要再次使用 .bind() 函数绑定对话框事件

于 2012-07-18T06:30:36.103 回答