虽然之前已经问了几次这个问题,但没有一个答案对我有帮助。因此,我再次问它......
我正在构建一个没有后端的网站的前端(没有服务器调用等)。我有一个显示内容的模式,带有next
和close
按钮。我的原始设计是,当按下next
按钮时,它会关闭打开的模态并打开一个具有不同内容的新模式。我认为这看起来不专业。我希望当用户按下next
按钮时,它会获取下一个模态的内容并将其显示在打开的模式上,而不必保持打开和关闭模态。但是,我不确切知道这是怎么回事。我假设这是可以用jQuery和AJAX完成的。我会附上我的代码。任何反馈都表示赞赏。
这是开放模式。当用户点击next
时,我希望将<h4 class="modal-title>
和<div class="modal-body>
的内容替换为下一个模式。
<div class="modal fade protein-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <!-- PROTEIN MODAL START-->
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"> Lean Protien </h4><!--CHANGE THIS WITH NEXT MODAL-->
</div>
<div class="modal-body"><!--CHANGE THIS WITH NEXT MODAL-->
<p>
At every meal, divide your plate into three equal sections. On one-third of the plate put some low-fat protein that is no larger or thicker than the palm of your hand (that’s because some hands are larger than others).
</p>
<p>
This doesn’t have to be animal protein, but it has to be protein-rich. For vegans this means either extra-firm tofu or soy imitation-meat products. For lacto-ovo vegetarians, it can also include dairy and egg protein-rich sources in addition to vegan sources of protein. For omnivores, the choice of proteins is even wider.
</p>
<div class="modal-image">
<img src="img/1-3plate1.png"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary zero-border" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success zero-border btn-next-slide-1" data-dismiss="modal">Next</button>
</div>
</div>
</div>
</div> <!-- PROTEIN MODAL END-->
h4和div应该用这个模态的h4和div替换
<div class="modal fade colorful-culinary-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <!-- COLORFUL-CULINARY MODAL START-->
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Colorful Carbohydrates</h4>
</div>
<div class="modal-body">
<p>
Next, fill the other two-thirds of your plate with colorful carbohydrates, primarily non-starchy vegetables and small amounts of fruits to balance the protein as shown below.
</p>
<p>
Here are two very practical hints when it comes to carbohydrates. First, the more white (white bread, white pasta, white rice, and white potatoes) you put on your plate, the more inflammation you are going to create. Second, the more non-starchy vegetables you consume and the fewer grains and starches you eat (ideally none), the better the results. Scientifically, it’s called lowering the glycemic load of the meal.
</p>
<div class="modal-image">
<img src="img/2-3plate1-1.png"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary zero-border" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success zero-border btn-next-slide-2" data-dismiss="modal">Next</button>
</div>
</div>
</div>
</div> <!-- COLORFUL-CULINARY MODAL END-->
目前,我只是打开和关闭模式,这是多余的。简单地替换文本会更有效率。
$(document).ready(function()
{
$('.colorful-culinary-button').click(function()
{
$('.colorful-culinary-modal').modal('show');
});
$('.protein-button').click(function()
{
$('.protein-modal').modal('show');
});
$('.fat-button').click(function()
{
$('.fat-modal').modal('show');
});
$('.btn-next-slide-1').click(function()
{
$('.colorful-culinary-modal').modal('show');
});
$('.btn-next-slide-2').click(function()
{
$('.fat-modal').modal('show');
});
$('.diet-builder-button').click(function()
{
$('.diet-builder-modal').modal('show');
});
});
答案 0 :(得分:0)
您可以按照此示例进行操作(需要根据您的代码进行调整,但这个想法应该有效)。
HTML(模态):
<div id="container">
<p>this is the first text in the modal</p>
</div>
<input id="nextBtn" type="button" value="NEXT"/>
jQuery的:
$(document).ready(function() {
var objPos = 1;
var ajaxReturnObj = ["this is the first text in the modal","this is the second text in the modal","this is the third text in the modal"];
$('#nextBtn').click(function(){
$('#container p').text(ajaxReturnObj[objPos]);
objPos++;
});
});
答案 1 :(得分:0)
如果你有一个静态页面,想要在不关闭下一个按钮的模态对话框的情况下更改内容,则需要静态地将内容存储在文件中。
我提出以下解决方案:
var eleToDisplay = ["next1", "next2"];
var indexOfEles = 0;
$('#btn').click(function () {
$("#dialog").dialog({
title: "Change text on Next without closing ",
resize: "auto",
modal: true,
buttons: {
"Next": function() {
$(this).html($('#' + eleToDisplay[indexOfEles]).html());
indexOfEles = ((indexOfEles + 1) >= eleToDisplay.length) ? 0 : indexOfEles + 1;
},
Close: function() {
$(this).dialog( "close" );
}
},
open: function() {
$(this).html($('#' + eleToDisplay[indexOfEles]).html());
indexOfEles = ((indexOfEles + 1) >= eleToDisplay.length) ? 0 : indexOfEles + 1;
$(this).parent().find('.ui-button:last').focus();
}
});
});
&#13;
body {
font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
font-size: 62.5%;
}
&#13;
<link href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.min.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-1.11.3.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<!-- Skeleton of default dialog -->
<div id="dialog" title="Basic dialog">
<p></p>
</div>
<!-- The first dialog content -->
<div id="next1" style="display:none">
<p>
At every meal, divide your plate into three equal sections. On one-third of the plate put some low-fat protein that is no larger or thicker than the palm of your hand (that’s because some hands are larger than others).
</p>
<p>
This doesn’t have to be animal protein, but it has to be protein-rich. For vegans this means either extra-firm tofu or soy imitation-meat products. For lacto-ovo vegetarians, it can also include dairy and egg protein-rich sources in addition to vegan sources of protein. For omnivores, the choice of proteins is even wider.
</p>
<div class="modal-image">
<img src="img/1-3plate1.png"/>
</div>
</div>
<!-- The second dialog content -->
<div id="next2" style="display:none">
<p>
Next, fill the other two-thirds of your plate with colorful carbohydrates, primarily non-starchy vegetables and small amounts of fruits to balance the protein as shown below.
</p>
<p>
Here are two very practical hints when it comes to carbohydrates. First, the more white (white bread, white pasta, white rice, and white potatoes) you put on your plate, the more inflammation you are going to create. Second, the more non-starchy vegetables you consume and the fewer grains and starches you eat (ideally none), the better the results. Scientifically, it’s called lowering the glycemic load of the meal.
</p>
<div class="modal-image">
<img src="img/2-3plate1-1.png"/>
</div>
</div>
<button id='btn'>Click me</button>
&#13;