Javascript 触发模态
我对触发模式有问题, 我检查jquery是否正确 我使用的是1.12.4版本,代码开头有标记:Javascript 触发模态,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我对触发模式有问题, 我检查jquery是否正确 我使用的是1.12.4版本,代码开头有标记: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 我的打开模式标签是: <a data-toggle="modal" class="modal-trigger" data-id="11" href="#komentarM"><
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
我的打开模式标签是:
<a data-toggle="modal" class="modal-trigger" data-id="11" href="#komentarM"></a>
我的模式代码是:
<div id="komentarM" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<input type="text" name="id" value=""></input>
<div class="modal-footer">
<a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
模态头
一串文字
使用此代码,我尝试使用触发器显示模式:
<script>
$(document).ready(function () {
$('#komentarM').on('shown.bs.modal', function () {
alert('da');
});
});
</script>
$(文档).ready(函数(){
$('#komentarM').on('show.bs.modal',function(){
警报(“da”);
});
});
请注意,显示了modal,但触发器不起作用。使用您提供的代码,我在
.html
文件中创建了它:
<!DOCTYPE html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</head>
<body>
<a data-toggle="modal" class="modal-trigger" data-id="11"
href="#komentarM">Howdy</a>
</body>
<div id="komentarM" onload="funtiontest()" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<input type="text" name="id" value=""></input>
<div class="modal-footer">
<a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
<script>
$(document).ready(function () {
$('#komentarM').on('shown.bs.modal', function () {
alert('da');
});
});
</script>
模态头
一串文字
$(文档).ready(函数(){
$('#komentarM').on('show.bs.modal',function(){
警报(“da”);
});
});
请注意,我在
标记中添加了Howdy
,用于触发模式。这样就有了一个用户可以点击的区域。我点击了链接,警报出现了,接着是模态。这适用于Safari 10.0.3。希望这会有所帮助。我认为您的html代码中没有错误。如下所示,它在Chrome/Firefox中正常工作。我希望这对你有用
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/css/materialize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<a data-toggle="modal" class="modal-trigger" data-id="11" href="#komentarM">Modal Open</a>
<div id="komentarM" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<input type="text" name="id" value=""></input>
<div class="modal-footer">
<a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#komentarM').on('shown.bs.modal', function () {
alert('da');
});
});
</script>
</body>
</html>
引导示例
模态头
一串文字
$(文档).ready(函数(){
$('#komentarM').on('show.bs.modal',function(){
警报(“da”);
});
});
首先:输入标记不需要关闭,因此我建议您删除输入的关闭标记,并保持如下状态:
<input type="text" name="id" value="">
Second:数据切换
和href
属性已经链接锚来打开模式,因此您不需要javascript函数,只需使用html代码即可
谢谢你,伙计:我现在正在添加
和它的作品!