我無法在此 PHP 檔案中呼叫我的模態,以便在以及 if 陳述句的值為 true 時呼叫
模態
<div id="myModal" class="modal fade" role="dialog">
<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>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
PHP 代碼
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<?php
// trying to target modal
if (true){
// not able to call
echo "$( document ).ready(function(){ $('#form').modal('show')";
}
else{
echo "alert(\"haha\")";
}
?>
請幫忙謝謝,所以當 if 陳述句為真但它不起作用時,它應該會打開一個彈出視窗。
謝謝!
uj5u.com熱心網友回復:
您只需要更改幾個專案即可讓您的彈出視窗正常作業。首先不要忘記腳本標簽中的右大括號,其次,確保使用相同的 ID,以便它知道要查找的內容。
//Your ID should match the ID of the modal you would like to open
<div id="myModal" class="modal fade" role="dialog">
<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>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
在您的腳本中,請務必從 myModal DIV 添加相同的 ID
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<?php
// trying to target modal
if (true){
// not able to call
echo "
<script type='text/javascript'>
$(document).ready(function(){
$('#myModal').modal('show'); //myModal is ID of div
}); //Don't forget your closing braces
</script>
";
}
else{
echo "alert(\"haha\")";
}
?>
uj5u.com熱心網友回復:
我們可以在頁面的任何位置撰寫 php 代碼,所以嘗試像這樣在 javascript 中撰寫 php 條件
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
<?php
if (true){
?>
$( document ).ready(function(){ $('#form').modal('show')});
<?php
}
else{
?>
alert("haha");
<?php
}
?>
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/437556.html
標籤:javascript php
上一篇:Laravel-驗證輸入是否在沒有0的區間[-1,10]內。not_in不能正常作業?
下一篇:Laravel觀察者和子/孫關系
