我的页面上有一个模态框,其内容根据单击两个按钮中的哪一个而变化( an<input />的值发生变化)。为了更好地添加功能,我设置了一个附加块,如果有错误显示,该块应该手动打开模态框。
为了确保表单“粘性”,我手动触发click相应按钮上的事件等等。但是,当我手动触发该click事件时,Bootstrap 不会添加.modal-open到正文中。由于我的网站是如何构建的,没有.modal-open在正文上,模态框完全隐藏在其他内容后面。
显然我做错了什么,但我不知道。这是我的代码的副本:
<?php
$modalerror = false;
$id = 0;
if (/*Basic check for errors*/) {
$modalerror = true;
$id = /*Get the correct id*/;
}
?>
<script type="text/javascript">
jQuery( document ).ready(function($) {
$('#modal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
if (button.attr('data-name') && button.attr('data-name') != '') {
$('#name').val(button.attr('data-name'));
} else {
$('#name').val('');
}
});
});
<?php if ($modalerror) { ?>
jQuery ( window ).load(function() {
jQuery('button[data-id=<?php echo …Run Code Online (Sandbox Code Playgroud) 鉴于这个模型:
+-----------+-------------+---------------------------+
| item_id | item_name | desc |
+-----------+-------------+---------------------------+
| 1 | Product 1 | lorem ipsum dolor... |
| 2 | Product 2 | lorem mauris eu... |
| 3 | Product 3 | scelerisque sagittis... |
| 4 | Product 4 | lorem dolor ipsum... |
| 5 | Product 5 | ipsum dolor lorem... |
+-----------+-------------+---------------------------+
Run Code Online (Sandbox Code Playgroud)
我想搜索包含其中lorem ipsum任何一个item_name或所有单词的所有产品desc.此外,任何单词都可以出现在lorem和之间ipsum,lorem并且ipsum可以按任何顺序出现.基本上,这个搜索将返回项目1,4以及 …