【问题标题】:jQueryUI on Laravel BladeLaravel Blade 中的 jQuery UI
【发布时间】:2015-02-14 10:01:29
【问题描述】:

我正在为我的 Laravel 应用程序实现 jQueryUI,我想要一个删除确认,但我没有实现一个。这是我的代码:

@foreach(array_chunk($items->all(), 3) as $row)
<div class="row" style="margin-bottom:40px;">

@foreach ($row as $item)
    <div class="col-md-4">

    <img src="{{$item->img_loc}}">
    <div>
    <strong>Breed: </strong>{{ $item->bname}}<br/>
    <strong>GameFarm: </strong>{{ $item->g_origin}}<br/>
    <strong>Leg Band: </strong>{{ $item->lband}}
    <h3><a href="{{ action('GamefarmsController@edit', $item->id) }}" >Edit</a>|<a id="thelink" href="#">Delete</a></h3>
    </div>

    </div>
@endforeach

这是我的 jQuery:

   <script>
        $(function()
        {
            $( "#dialog-confirm" ).dialog(
            {
                autoOpen: false,
                resizable: false,
                height:140,
                modal: true,
                buttons:
                {
                    "Delete": function()
                    {
                        $( this ).dialog( "close" );
                    },
                    Cancel: function()
                    {
                        $( this ).dialog( "close" );
                    }
                }
            });
        });
    </script>

我想通过这段代码让程序重定向到我的控制器,这会携带 $items->id 在顶部代码中循环,就像编辑一样。

{{ action('GamefarmsController@delete', $item->id) }}

我尝试对此代码进行试验,但没有任何反应。

编辑:这是剩余的脚本:

 <script type="text/javascript">
     $(document).ready(function(){
        $('#thelink').click(function(){ $('#dialog-confirm').dialog('open'); });
     });
 </script>

【问题讨论】:

  • 您现在是否收到确认对话框,如果是,请发布整个 jquery 代码
  • 是的,等我更新一下
  • 检测用户是否确认删除的功能是什么?
  • 这是我在更新中发布的最后一个代码

标签: php jquery mysql laravel blade


【解决方案1】:

添加href作为删除链接如下

<a class="confirmLink" href="{{ action('GamefarmsController@delete', $item->id) }}">Delete</a>

然后在js

<script type="text/javascript">
  $(document).ready(function() {
    $("#dialog-confirm").dialog({
      autoOpen: false,
      modal: true
    });
  });

  $(".confirmLink").click(function(e) {
    e.preventDefault();
    var targetUrl = $(this).attr("href"); // get the url of // href="{{ action('GamefarmsController@delete', $item->id) }}"

    $("#dialog-confirm").html("Confirm Dialog Box");

    $("#dialog-confirm").dialog({
       title: "confirmation",
       buttons: {
          "Delete": function () {
              $(this).dialog('close');
              window.location.href = targetUrl; // change browser path to url in delete link
           },
           "Cancel": function () {
              $(this).dialog('close');
              callback(false);
           }
       }
    });

    $("#dialog-confirm").dialog("open");
  });
</script>

【讨论】:

    猜你喜欢
    • 2017-08-13
    • 2016-09-02
    • 2019-11-11
    • 2017-10-03
    • 2017-12-06
    • 2015-07-10
    • 2017-04-14
    • 1970-01-01
    • 2014-10-06
    相关资源
    最近更新 更多