你好可以在从函数中获取结果后打开一个模态吗?我想要做的是,我在模态中有一个链接按钮,然后在单击时将一些参数传递给将返回结果的函数。
现在我想在另一个模态中显示结果并关闭上一个模态,这是否可能我在互联网上查看但我没有找到解决我特定问题的方法。
以下是我正在处理的代码:
<button type="button" class="btn btn-info btn-lg btn-transparent" data-toggle="modal" data-target="#firstyearmodal">
<span style="font-size:1.5em;" class="glyphicon glyphicon-search"></span>
</button>
<div class="modal modal-wide fade" id="firstyearmodal" role="dialog">
<!--class="modal fade"-->
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<!--modal body-->
<div class="modal-body">
//this is the part where the user clicks the link then the modal fyft modal will show up
<?= HTML::a('<span style="font-size:1.5em;" class="glyphicon glyphicon-search"></span>',
['site/SubjectEquivalent', 'subjectcode' => $subjects['subjectcode']],
['data-method' => 'post']) ?>
<!--end of modal body-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
<!--end of modal content-->
</div>
</div>
<!--modal 1 for free section-->
<!--First Year Modal-->
</div>
<div class="modal modal-wide fade" id="fyftmodal" role="dialog">
<!--class="modal fade"-->
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<!--modal body-->
<div class="modal-body">
//sample modal to show the process
<!--end of modal body-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
<!--end of modal content-->
</div>
</div>
<!--modal 1 for free section-->
<!--First Year Modal-->
</div>
我发现了一个类似的代码,但它只触及了css方面,而不是我获取数据的部分。
编辑1
//controller
public function SubjectEquivalent($subjectcode){
$model = new SubjectEquivalent();
return $model->SubjectEquivalent($subjectcode);
}
//view file and where the foreach method happens
<?php foreach($firstyearfirstterm as $subjects):?>
<table class="table table-bordered">
<th>Subject</th>
<th>Schedule</th>
<th>Section</th>
<th>Action</th>
<th>Slots</th>
<th>Status</th>
<th>Equivalent Subjects</th>
<tr>
<td style="width:130px">
<?= $subjects['subjectcode']; ?>
</td>
<td><?= $subjects['schedday'] . ' ' . $subjects['schedtime'] ?></td>
<td><?= $subjects['section'] ?></td>
<td style="width:130px">
<!-- base() -> site/function -->
<!-- <a href="<?php // Url::base(); ?>test" class="btn-info btn-transparent btn-large">ADD</a> -->
<!-- SYNTAX - HTML::a('text', ['controller/function', 'value after / of controller/function' => actual value],
['class' => 'class of the a component']) -->
<?php //if(ActiveSubject::find()->select(['clientid', 'subjectid'])
// ->andWhere(['clientid' => $_user,])
// ->andWhere(['subjectid' => $subjects['subjectid'],])):
/* ActiveSubject::find()->where(['clientid' => $_user,
'subjectid' => $subjects['subjectid'],])*/
//ActiveSubject::isAdded($_user, $subjects['subjectid'])
//Check if records exists in a table
$isAdded = ActiveSubject::find()->where(['clientid' => $_user,'TrNo' => $subjects['TrNo'],])->exists();
$isFinished = FinishedSubjects::Checkprereq($subjects['TrNo'], $_user);
//read from subject container if exact sched is existing
//http://notepad.pw/samplees
// $isConflict = ActiveSubject::find()->where(['schedday' => $subjects['schedday'],
// 'schedtime' => $subjects['schedtime']])->exists();
if($isAdded):
// ActiveSubject::find()->where(['clientid' => $clientid,
// 'subjectid' => $subjects['subjectid'],]);
// echo ActiveSubject::find()->where(['clientid' => $clientid, 'subjectid' => $subjects['subjectid']])
// ->createCommand()->sql;
//make a function that returns a boolean form the activesubject model.see stackoverflow.
?>
<b class="text-muted"><p>ADDED</p></b>
<?php elseif($subjects['slots'] == 0 || $subjects['slots'] == $subjects['asqa']): ?>
<b class="text-muted">N/A</b>
<?php elseif($isFinished == false): ?>
<b class="text-muted">Pre requisite not completed</b>
<?php else: ?>
<p>
<?= Html::a('<b>ADD</b>',
['site/addsubject', 'TrNo' => $subjects['TrNo'], 'clientid' => $_user],
['class' => 'btn-info btn-transparent btn-large', 'data-method' => 'post']) ?>
</p>
<?php endif; ?>
</td>
<td>
<p> <?= $subjects['slots'] ?> </p>
</td>
<td>
<?php if($isAdded): ?>
<b class="text-primary"><p>Awaiting Confirmation</p></b>
<?php elseif($isFinished == false): ?>
<b class="text-muted">Pre requisite not completed</b>
<?php elseif($subjects['slots'] == 0 || $subjects['slots'] == $subjects['asqa']): ?>
<b class="text-primary">No more slots</b>
<?php else: ?>
<table>
<tr>
<td><b class="text-primary">Approved: <?= $subjects['asqa']; ?></b></td>
<td><b class="text-primary"> Pending: <?= $subjects['astempqa']?></b></td>
</tr>
</table>
<?php endif; ?>
</td>
<td>
<p>
<?php
//This is where I wanted to show the modal for when i click the button then show the result another modal
//HTML::a('<span style="font-size:1.5em;" class="glyphicon glyphicon-search"></span>',
// ['site/SubjectEquivalent', 'subjectcode' => $subjects['subjectcode']],
// ['data-method' => 'post']) ?>
<!-- <a href="#my_modal" data-toggle="modal" data-book-id="<?php // $subjects['subjectcode'] ?>">Open Modal</a>
<div class="modal" id="my_modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Modal header</h4>
</div>
<div class="modal-body">
<p>some content</p>
<input type="text" name="bookId" value=""/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> -->
</p>
</td>
</tr>
</table>
<?php endforeach; ?>
// This is what happens in the model (where the query should happen) don't mind the controller i just use it to pass through data.
<?php
namespace app\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
class SubjectEquivalent extends ActiveRecord{
public static function tableName(){
return '{{%subjectequivalent}}';
}
public static function SubjectEquivalent($subjectcode){
return static::find()
->where(['subjectmain' => subjectcode])
->asArray();
->all();
}
}
?>
答案 0 :(得分:0)
你在找这样的东西吗?
$("#close1_open2").click(function() {
var sum = parseInt($('#fnum').val(), 10)+parseInt($('#fnum').val(), 10);
$("#sum").text(sum);
$("#modal1").modal('hide');
$("#modal2").modal('show');
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<button class="btn btn-primary" data-toggle="modal" data-target="#modal1">modal 1</button>
<div id="modal1" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<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">Modal title</h4>
</div>
<div class="modal-body">
<p>this is modal no. 1</p>
<input type="text" id="fnum" />
<input type="text" id="snum" />
<button id="close1_open2" type="button" class="btn btn-primary">close & open modal 2</button>
</div>
</div>
</div>
</div>
<div id="modal2" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<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">Modal title</h4>
</div>
<div class="modal-body">
<p>sum of two number is :
<span id="sum"></span>
</p>
</div>
</div>
</div>
</div>
&#13;