Bootstrap:使用表单参数使用ajax加载模式

时间:2022-10-13 15:18:51

I page a page with several forms with buttons, like this:

我在页面上打了几个带按钮的表单,如下所示:

<form name="openconfirm">
    <input type="hidden" name="itemid" value="123">
    <button type="submit" class="btn btn-sm btn-success ">Item 123</button>
</form>
<form name="openconfirm">
    <input type="hidden" name="itemid" value="124">
    <button type="submit" class="btn btn-sm btn-success ">Item 125</button>
</form>
<form name="openconfirm">
    <input type="hidden" name="itemid" value="125">
    <button type="submit" class="btn btn-sm btn-success ">Item 125</button>
</form>

Each button should open a bootstrap modal with more info about the selected item (so the modal content should be loaded from a remote page which has been passed the itemid param using POST or GET ?)

每个按钮应该打开一个bootstrap模式,其中包含有关所选项目的更多信息(因此模式内容应该从远程页面加载,该页面已经使用POST或GET传递了itemid参数?)

I believe it should be something like this:

我相信它应该是这样的:

<script>
  $(function(){
      $('form[name="openconfirm"]').on('submit', function(){
       itemid = itemid input from form; <- Not actual code
       openModal(#myModal, "file.php?itemid=" + itemid); <- Not actual code
      })
  })
</script>

I hope you can understand what I need and provide me with some solution. I would be thankful if you could provide me actual code since I'm new to javascript. I'm open to better alternatives from the one I've provided.

我希望你能理解我需要的东西,并为我提供一些解决方案。如果你能提供我真正的代码,我会很感激,因为我是javascript的新手。我愿意接受我提供的更好的选择。

Many thanks

1 个解决方案

#1


1  

Try with this HTML markup

尝试使用此HTML标记

<button type="button" data-toggle="modal" data-target="#myModal" id="123" class="btn someclass">Item 123</button>
<button type="button" data-toggle="modal" data-target="#myModal" id="124" class="btn someclass">Item 124</button>
<button type="button" data-toggle="modal" data-target="#myModal" id="125" class="btn someclass">Item 125</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">LOADED CONTENT</div>
    </div>
</div>

and this jQuery

和这个jQuery

$(function () {
    $('.someclass').on('click', function () {
        var itemid = $(this).attr('id');
        $(".modal-content").load("/file.php?itemid=" + itemid);
    });
});

http://jsfiddle.net/3dSPw/1/

Currently, this doesn't load any new content because URL /file.php?itemid=123 it's not existent, but try it on your existing project.

目前,这不会加载任何新内容,因为URL /file.php?itemid=123它不存在,但在现有项目上尝试。

#1


1  

Try with this HTML markup

尝试使用此HTML标记

<button type="button" data-toggle="modal" data-target="#myModal" id="123" class="btn someclass">Item 123</button>
<button type="button" data-toggle="modal" data-target="#myModal" id="124" class="btn someclass">Item 124</button>
<button type="button" data-toggle="modal" data-target="#myModal" id="125" class="btn someclass">Item 125</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">LOADED CONTENT</div>
    </div>
</div>

and this jQuery

和这个jQuery

$(function () {
    $('.someclass').on('click', function () {
        var itemid = $(this).attr('id');
        $(".modal-content").load("/file.php?itemid=" + itemid);
    });
});

http://jsfiddle.net/3dSPw/1/

Currently, this doesn't load any new content because URL /file.php?itemid=123 it's not existent, but try it on your existing project.

目前,这不会加载任何新内容,因为URL /file.php?itemid=123它不存在,但在现有项目上尝试。