gpt4 book ai didi

php - 如何将 PHP 数组传递给 jQuery 函数?

转载 作者:行者123 更新时间:2023-11-29 22:22:52 26 4
gpt4 key购买 nike

我有一个打开模态弹出窗口的 jQuery 函数,我在同一个文件中有一个 PHP 变量,如 $url="iteminfo.php?ID=".$i['itmid'];($i['itmid'] 是MySQL中部分产品的id)。 jQuery 函数如下所示:

<script type="text/javascript">

$(document).ready(function(Surl) {

var source="iteminfo.php?ID=<?echo $i['itmid']?>";
var width = 920;
var align = "center";
var top = 100;
var padding = 10;
var backgroundColor = "#FFFFFF";
var borderColor = "#000000";
var borderWeight = 4;
var borderRadius = 5;
var fadeOutTime = 300;
var disableColor = "#666666";
var disableOpacity = 40;
var loadingImage = "js/popup/loading.gif";

$(".modal").click(function() {

modalPopup( align,
top,
width,
padding,
disableColor,
disableOpacity,
backgroundColor,
borderColor,
borderWeight,
borderRadius,
fadeOutTime,
source,
loadingImage );

});

$(document).keyup(function(e) {
if (e.keyCode == 27) {
closePopup(fadeOutTime);
}
});

});

</script>

它会打开相应的链接,但函数会像循环一样打开所有链接。如何将 $url 传递到 jQuery 函数中以打开相应产品的相应链接?

最佳答案

对于初学者来说,它看起来更像是这样,但如果没有看到您的 HTML 代码,就很难说出您将如何提取每个具有 ID 的不同对象的 ID。

  <script type="text/javascript">

$(document).ready(function(Surl) {


var source="iteminfo.php?ID=";
var width = 920;
var align = "center";
var top = 100;
var padding = 10;
var backgroundColor = "#FFFFFF";
var borderColor = "#000000";
var borderWeight = 4;
var borderRadius = 5;
var fadeOutTime = 300;
var disableColor = "#666666";
var disableOpacity = 40;
var loadingImage = "js/popup/loading.gif";


$(".modal").click(function() {

//get the id of what you're opening on each click event.
var myid = ...

modalPopup( align,
top,
width,
padding,
disableColor,
disableOpacity,
backgroundColor,
borderColor,
borderWeight,
borderRadius,
fadeOutTime,
source + myid,
loadingImage );

});


$(document).keyup(function(e) {
if (e.keyCode == 27) {
closePopup(fadeOutTime);
}
});

});

</script>

关于php - 如何将 PHP 数组传递给 jQuery 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11368278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com