【问题标题】:Dynamic parameters for dynamic contents with qTip使用 qTip 的动态内容的动态参数
【发布时间】:2010-08-12 03:04:43
【问题描述】:

我想用 qTip 传递一个动态参数,但它失败了。 my_ajax_controller.php 只显示变量类型,不显示 q。

$('a.menu_help').qtip({
    content: {
      url:'my_ajax_controller.php',
      data: 'type=help_menu&q='+$(this).attr('id'),
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
});

但是,q 的静态值有效:

$('a.menu_help').qtip({
    content: {
      url:'my_ajax_controller.php',
      data: 'type=help_menu&q=toto',
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
});

有没有办法将动态值传递给参数数据?

提前致谢!

弗洛伦特

【问题讨论】:

    标签: jquery ajax qtip


    【解决方案1】:

    试试这样的:

    $('a.menu_help').each(function(){
        $currentLink = $(this);
        $currentLink.qtip({
            content: {
              url:'my_ajax_controller.php',
              data: 'type=help_menu&q='+$currentLink.attr('id'),
              method: 'get'
            },
            show: 'mouseover',
            hide: 'mouseout'
    });
    

    我没有对此进行测试,但我做过类似的事情。只是现在找不到。

    【讨论】:

    • 如果你一次性给他们小费,性能应该不会有太大的不同。
    【解决方案2】:

    我有同样的问题,我用这段代码解决了。适用于 qtip 1.0 rc3 和 JQuery 1.4.2。 请注意,qtip 与 jquery>1.3 有问题。谷歌获取相关信息,但很容易修复在 jquery.qtip.js 上添加一行

    $('.username_link').each(function(){
       $(this).click(function(){ return false });//JS enabled => link default behavior disabled. Gaceful degradation
       $(this).qtip({
       content: { url: '/users/links',
                  data: { id: $(this).attr('data-id') },
                  method: 'post'
                },
       show: 'click',
       hide: 'mouseout'
       })
    });
    

    【讨论】:

      【解决方案3】:

      它应该可以工作,但只是尝试查看您作为 ID 传递的内容,或将数据作为集合传递,例如:

      数据:{'type':'help_menu', 'q':id}

      或者

      $('a.menu_help').qtip({ var id = $(this).attr('id'); 警报(ID); 内容: { url:'my_ajax_controller.php', 数据:'type=help_menu&q='+ id, 方法:'得到' }, 显示:'鼠标悬停', 隐藏:'mouseout' });

      【讨论】:

      • 我确认这行不通,您正在对象定义中进行分配。你会得到一个missing : after property id
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 2016-11-07
      • 2019-07-03
      相关资源
      最近更新 更多