简体   繁体   English

在模式框中打开页面

[英]Open page in modal box

I have a script that restrict the click on a href link if there;s no checkbox selected. 我有一个脚本,如果没有选择复选框,该脚本会限制对href链接的单击。 I want the editpr.php open in modal box. 我想在模式框中打开editpr.php。 The problem is I'm not familiar with modalbox. 问题是我对modalbox不熟悉。 Any help? 有什么帮助吗?

<a class="button edit" style="cursor:pointer;" ><span><b>Edit Purchase Request</b></span></a>
<a class="button remove" style="cursor:pointer;" name="remove"><span><b>Remove Purchase Request</b></span></a> 

This is my script 这是我的剧本

jQuery(function ($) {
    $('a.button.edit, a.button.remove').click(function () {
        if ($('input[name="checkbox[]"]:checked').length == 0) {
            return;
        }

        if (!confirm('Do you want to continue?')) {
            return
        }

        var frm = document.myform;
        if ($(this).hasClass('edit')) {
            frm.action = 'editpr.php';
        }
        if ($(this).hasClass('remove')) {}
        frm.submit();
    })
})

You can't open a page in a modal box just with pure javascript, as "alert()" or "confirm()". 您不能仅使用纯JavaScript在模式框中打开页面,如“ alert()”或“ confirm()”。

To do what you want you need to put your 'editpr.php' content inside a div, and make it modal with CSS. 要执行您想要的操作,您需要将您的'editpr.php'内容放入div中,并使用CSS将其设置为模态。

Actually we have a lot of libraries that make it happen easily, I think that most used is: http://www.jacklmoore.com/colorbox/ 实际上,我们有很多可以轻松实现的库,我认为使用最多的库是: http : //www.jacklmoore.com/colorbox/

Check the "Outside HTML (Ajax)" and "Outside Webpage (Iframe)" on this example page, probably is the same thing that you want to do: http://www.jacklmoore.com/colorbox/example1/ 检查此示例页面上的“外部HTML(Ajax)”和“外部网页(Iframe)”,可能与您要执行的操作相同: http : //www.jacklmoore.com/colorbox/example1/

There are some useful jQuery plugins that can make your job really easy. 有一些有用的jQuery插件可以使您的工作变得非常轻松。 I suggest you give them a try. 我建议您尝试一下。 Here you have an example. 这里有一个例子。

Since you are already using jQuery you could use jquery-ui. 由于您已经在使用jQuery,因此可以使用jquery-ui。

They have an exmple of what you want to do here: http://jqueryui.com/dialog/#modal 他们有您要在此处执行的操作的示例: http : //jqueryui.com/dialog/#modal

Once you get your modal dialog element setup, all you have to do is make and XHR for editpr.php, load the result into the elements innerhtml, then display the dialog. 一旦完成了模态对话框元素的设置,您要做的就是make和XHR for editpr.php,将结果加载到元素innerhtml中,然后显示对话框。

// setup your modal dialog
var el = $( "#editpr-dialog" ).dialog({
  // ... (other config options)
  modal: true
});

// XHR editpr.php and show the dialog box
$.get('editpr.php', function(data){
  el.html(data).dialog('open');
});

custombox插件具有许多漂亮的功能,并且可以与Jquery惊人地协同工作: http ://dixso.github.io/custombox/

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

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