简体   繁体   English

我的模式无法从 Laravel 中的 jquery 脚本接收数据

[英]My modal can not receive data from jquery script in Laravel

So I have modal script like this:所以我有这样的模态脚本:

<div class="modal" id="assignstore" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
.....some of code.....
        <div class="row mb-3">
           <label for="name" class="col-md-4 col-form-label  text-md-end">
              {{ __("Subject") }}
            </label>
                 <div class="col-md-6">
                     <input id="title-as">
                 </div>
         </div>
    </div>
</div>

And I have data from here:我有来自这里的数据:

<a href="#" 
    data-target="#assignstore" 
    data-toggle="modal" 
    data-titleas="{{ $subject->title }}"
    data-idas="{{ $subject->id }}" 
    class="a btn btn-warning"
>
    Assignment 
</a>

This is my Jquery Script:这是我的 Jquery 脚本:

<script>
    $('#assignstore').on('show', function(e) {
        var link = e.relatedTarget(),
            modal = $(this),
            id = link.data("idas"),
            title = link.data("titleas");

        modal.find("#title-as").val(title);
        modal.find("#id-as").val(id);
    });
</script>

Could you help me to find out what's wrong with my script?你能帮我找出我的脚本有什么问题吗?

it depends what error you receive .取决于您收到什么错误 btw here is some solutions (maybe it works for you):顺便说一句,这里有一些解决方案(也许对你有用):

  1. replace your script (make sure jquery runs before ur script)替换你的脚本(确保 jquery 在你的脚本之前运行)
  2. change the way ur script fires改变你的脚本触发的方式
  3. what is $subject on ur code?您的代码中的$subject是什么? if it is an item of an array we should know what is this item (make sure u r calling items well)如果它是数组的一个项目,我们应该知道这个项目是什么(确保你 r 调用项目很好)

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

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