[英]How can I use the input parameter value passed to a JavaScript function into the popup opened by this JS function?
I am not so into PHP and JavaScript and I have the following problem trying to pass a value from a main page to a popup page (defined into this main page). 我不太喜欢PHP和JavaScript ,尝试将值从主页传递到弹出页面(定义到该主页)时遇到以下问题。 I try to explain my situation in details:
我尝试详细解释我的情况:
I have an account.php page containing this link: 我有一个account.php页面,其中包含以下链接:
<a href="#" onclick="doRemoveBooking();">
<i class="fa fa-times"></i>
</a>
Clicking on this link it is performed the doRemoveBooking() JavaScript function that is defined in the same page into this block: 单击此链接,将执行在此块的同一页面中定义的doRemoveBooking() JavaScript函数:
<script type="text/javascript">
//metodo richiamato al click del bottone "RIVENDI"
function doRemoveBooking(id){
console.info("Into doRemoveBooking");
$('.popUpRemoveBooking').magnificPopup({
items: {
src: '#remove-booking-popup'
}
// (optionally) other options
}).magnificPopup('open');
}
</script>
that opens a popup defined at the end of the dame account.php page by this div element: 该打开由以下div元素在dame account.php页面末尾定义的弹出窗口:
<div class="popUpRemoveBooking">
<div id="remove-booking-popup" class=" white-popup-block mfp-hide">
<div class="fluid-container">
<div class="row">
<h2><?php echo $texts['CANCEL_BOOKING'] ?></h2>
<p>Sei veramente sicuro di voler cancellare la prenotazione?</p>
<?php echo $id_booking; ?>
</div>
</div>
</div>
</div>
This popup is correctly opened but I obtain an error message when it try to render this line: 正确打开了此弹出窗口,但是在尝试渲染此行时出现错误消息:
<?php echo $id_booking; ?>
I know that it is wrong. 我知道那是错的。 As you can see my JavaScript function take an id as parameter:
如您所见,我的JavaScript函数将id作为参数:
doRemoveBooking(id)
How can I print this id received as input parameter from the JavaScript function used to open the popup in the popup body? 我该如何打印从用于在弹出式正文中打开弹出式窗口的JavaScript函数作为输入参数接收到的此ID ? (instead the wrong
(而不是错误的 ).
)。 What is a smart and neat way to do it?
什么是聪明又整洁的方法呢?
Replace <?php echo $id_booking; ?>
替换
<?php echo $id_booking; ?>
<?php echo $id_booking; ?>
with <span id="bookingID"></span>
<?php echo $id_booking; ?>
与<span id="bookingID"></span>
Then replace the content of that <span>
in your function: 然后在函数中替换该
<span>
的内容:
function doRemoveBooking(id){
console.info("Into doRemoveBooking");
$('#bookingID').html(id); // <---------------- Add this line
$('.popUpRemoveBooking').magnificPopup({
items: {
src: '#remove-booking-popup'
}
// (optionally) other options
}).magnificPopup('open');
}
Don't forget to call doRemoveBooking(id)
with the correct booking-id ! 不要忘记使用正确的预订ID致电
doRemoveBooking(id)
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.