gpt4 book ai didi

javascript - 如何将 id 传递给文件

转载 作者:行者123 更新时间:2023-12-01 03:25:04 25 4
gpt4 key购买 nike

当我将鼠标悬停在“homepage_game”-div 上时,我想将 id(“data-gameid”)传递给名为 game_get_info.php 的文件。

请问如何通过 Javascript 或 jQuery 完成此操作? TIA

这是 php 代码:

<?php echo '
<div class="homepage_game home_tooltip" data-gameid="'.$game_cat_content['id'].'">
<div class="home_game_image">
<a href="'.$game_cat_content['url'].'">
<img class="home_thumb" src="'.$game_cat_content['image_url'].'" height="85" width="125" alt="'.$game_cat_content['name'].'"/>
</a>
</div>
</div>';
?>

这是 JS/jQuery 代码:

<script type="text/javascript">
$(document).ready(function() {
$('.tooltipstered').tooltipster('destroy');
$('.home_tooltip').tooltipster({
trigger: 'hover',
animation: 'fade',
animationDuration: 250,
delay: 1000,
onlyOne: true,
position: 'top',
contentAsHTML: true,
interactive: true,
theme: ['tooltipster-noir', 'tooltipster-noir-customized'],

content: 'Loading...',

functionBefore: function(instance, helper) {

var $origin = $(helper.origin);

if ($origin.data('loaded') !== true) {

$.post('<?php echo $setting['template_url']; ?>/sections/ajax/game_get_info.php, function(data) {

instance.content(data);

});
}
}
});
});
</script>

最佳答案

试试这个:

<script type="text/javascript">
$(document).ready(function() {
$('.tooltipstered').tooltipster('destroy');
$('.home_tooltip').tooltipster({
trigger: 'hover',
animation: 'fade',
animationDuration: 250,
delay: 1000,
onlyOne: true,
position: 'top',
contentAsHTML: true,
interactive: true,
theme: ['tooltipster-noir', 'tooltipster-noir-customized'],

content: 'Loading...',

functionBefore: function(instance, helper) {

var $origin = $(helper.origin);

if ($origin.data('loaded') !== true) {

var itemId = $origin.attr('data-gameid');

jQuery.ajax({
type: "POST",
url: "<?php echo $setting['template_url']; ?>/sections/ajax/game_get_info.php",
data: {
itemId: itemId
},

beforeSend: function(){

},

success: function(data){

instance.content(data);

}

});

}
}
});
});
</script>

关于javascript - 如何将 id 传递给文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44890199/

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