【发布时间】:2018-09-16 03:50:47
【问题描述】:
我有一个有按钮的页面。当用户点击按钮时,会弹出一个引导模式窗口。模态窗口有两个按钮“关闭”和“保存”。
根据引导网站,“关闭”将关闭窗口,并且不会对该页面触发任何操作。但是,我想要的是当用户单击另一个按钮(例如“保存”)时,应该发生一些操作(通过使用 PHP)。 如果使用 php 不容易,那么使用 javascript 或 jquery 的任何其他方法也可以,但如何做到这一点? 有人能解释一下如何让“保存”按钮执行一些操作吗?
作为参考,我复制了引导网站中提到的代码。
JSbin链接:https://jsbin.com/rebuwuvefe/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
您不能使用 php 检查按钮点击。请自学
client-side和server-side的含义。 -
@eisbehr 是对的。您可以尝试通过 javascript 向按钮添加事件侦听器。
-
如果你要使用jQuery,有基本的例子here
-
@eisbehr:我们可以使用 php 通过将按钮保留在表单中来检查按钮点击。我知道
client-side和server-side。我比 jquery 更熟悉 php。这就是为什么在这种情况下尝试使用 php。 -
你在说什么?您不能为此使用 php。您可能意味着将 php 与
$_POSTvar 一起使用,但您无法直接在 html 中处理按钮单击。这就是 js 的用途。
标签: javascript php jquery bootstrap-modal