【问题标题】:How to pass an id to a file如何将id传递给文件
【发布时间】:2017-07-03 16:22:27
【问题描述】:

当我将鼠标悬停在 '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>

【问题讨论】:

  • 你所在的页面是game_get_info.php吗?
  • 您忘记了数据:。

标签: javascript jquery tooltipster


【解决方案1】:

试试这个:

<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>

【讨论】:

    猜你喜欢
    • 2020-11-23
    • 2015-04-13
    • 2018-11-16
    • 1970-01-01
    • 2020-09-29
    • 2019-04-08
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多