【问题标题】:Need help with this script需要有关此脚本的帮助
【发布时间】:2010-07-31 11:07:58
【问题描述】:

我正在使用以下脚本在我的动态页面上获取 Gravatar,

<input type="text" id="email" value="{$clientemail}" style="display:none;"/> 

  $(document).ready(function(){           
                $('.p').append($.gravatar($('#email').val(), {
                method: 'append',
                size: '100',
                image: '/images/1.png',
                rating: 'r'
            }));
        }); 


<div class="p" style="width:100px;height:100px">

我必须使用来自另一个页面的以下代码加载 {$clientemail} 的值。

$('#email').load('clientarea.php? #clientemail');

我的问题是 .load 需要几秒钟才能加载,所以 .append 正在发送空值,导致默认 Gravatar 图片。

我该如何克服这个问题??

谢谢

【问题讨论】:

  • 您是否 100% 确定 #email 包含有效的电子邮件地址?

标签: jquery


【解决方案1】:

您需要将附加代码粘贴在load 回调中,如下所示:

$('#email').load('clientarea.php? #clientemail' function() {
  $('.p').append($.gravatar($(this).val(), {
            method: 'append',
            size: '100',
            image: '/images/1.png',
            rating: 'r'
        }));
});

虽然不建议将.load() 放入这样的输入元素,但最好使用$.get() 请求并获取该值,如下所示:

$.get('clientarea.php?', function(data) {
  var val = $('#clientemail', data).val();
  //if needed: $('#email').val(val);
  $('.p').append($.gravatar(val, {
            method: 'append',
            size: '100',
            image: '/images/1.png',
            rating: 'r'
        }));
});

【讨论】:

    猜你喜欢
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2017-08-02
    • 1970-01-01
    相关资源
    最近更新 更多