简体   繁体   English

如何使用传递给JavaScript函数的输入参数值到此JS函数打开的弹出窗口中?

[英]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). 我不太喜欢PHPJavaScript ,尝试将值从主页传递到弹出页面(定义到该主页)时遇到以下问题。 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.

相关问题 如何在JavaScript函数中使用传递的参数? - How can I use a passed parameter in a JavaScript function? 如何检查传递给javascript函数的参数值是否为空? - How can I check if the value of a parameter passed to a javascript function is null? 如何编写一个JavaScript函数,该函数将调用作为参数传递的另一个函数? - How can I write a JavaScript function that will call another function passed as a parameter? 我可以在要传递到循环中的箭头函数的参数中使用for循环迭代器吗? - Can I use a for loop iterator in the parameter of an arrow function to be passed into the loop? 在JavaScript中,如何使用函数参数作为对象的键? - In JavaScript how can I use a function parameter as the key to an object? 如何使用javascript访问在函数中传递的对象参数? - How do I access object parameter passed in a function using javascript? 如何使JavaScript函数等待输入或值? - How can I make a JavaScript function wait for input or value? 如何使 JS function 在新打开的 window 上工作? - How can I make a JS function work on a new opened window? 如何创建将传递的参数视为文字的 function? - How can I create a function which treats a passed parameter as a literal? 如何根据传递给函数的参数更改变量名? - How can I change a variable name based on a parameter passed to a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM