简体   繁体   English

将变量从URL传递到简单模态弹出窗口

[英]Pass Variable To Simple Modal Popup From URL

Have a table created from a sql query am trying to pass the variable pmntid via the following code: 有一个通过sql查询创建的表正试图通过以下代码传递变量pmntid:

?>
<td class="listingTextLeft">
<a href="?pmntid=<?php echo $row[0] ?>" class="pmntDetail"><?php echo $row[20] ?></a>
</td>
<?php

The link shows the correct pmntid however I am unable to pass it through the following jquery: 链接显示了正确的pmntid,但是我无法通过以下jquery传递它:

    <script>
    jQuery('.pmntDetail').each(function(i,v){
        jQuery(v).click(function(paymentID){
         paymentID.preventDefault();
         paymentID.stopPropagation();
         var pmntid = <?php echo $row[0]; ?>
         console.log("ID: ", pmntid);
         $("#pmntDetailPopup").modal({position: ["5%"]});
      });

 });
    </script>

The console log shows pmntid as undefined. 控制台日志将pmntid显示为undefined。 I need this pmntid passed to a simple modal popup which displays in the pmntDetailPopup div on the same page where I run a sql query to populate fields with results from the query. 我需要将此pmntid传递到一个简单的模式弹出窗口,该弹出窗口显示在同一页上的pmntDetailPopup div中,在该页面上运行SQL查询以使用查询结果填充字段。

The popup works fine and all fields are populated if I use a constant in the query so the error is definitely in passing the pmntid. 如果我在查询中使用常量,则弹出窗口可以正常工作,并且所有字段都已填充,因此错误肯定是通过pmntid传递的。

Use a data attribute: 使用数据属性:

<a href="?pmntid=<?php echo $row[0] ?>" data-rid="<?php echo $row[0] ?>" class="pmntDetail"><?php echo $row[20] ?></a>

and read it in the click event 并在点击事件中阅读

var pmntid = $(this).data("rid");
console.log("ID: ", pmntid);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM