如何将 id 传递给文件
How to pass an id to a file
当我悬停 '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-code:
<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>
当我悬停 '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-code:
<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>