0

目前我的代码是:

<!DOCTYPE html>
<head>

    <title>Search Tweets</title>
<style type = "text/css">

#tweets{
    border: 1px solid red;
    text-align: center;
    font-family: cursive;
}
#box{
    float: left;
    margin-left: auto;
    margin-right: auto;

}
#btn{
    margin-left: auto;
    margin-right: auto;
}
#main{
    padding-bottom: 20px;
}




</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">

$(document).ready(function() {
    $('#submit').click(function() {
        var params = {
            q: $('#query').val(),
            rpp: 10
        };
        searchTwitter(params);
    });

function searchTwitter(query) {
    $.ajax({
        url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
        dataType: 'jsonp',
        success: function(data) {
            var tweets = $('#tweets');
            tweets.html('');
            for (res in data['results']) {
                tweets.append('<div>' + data['results'][res]['profile_image_url'] + data['results'][res]['from_user'] + ' Said: <p>' + data['results'][res]['text'] + '</p></div><br />');

            }
        }
    });
    }
});


</script>

</head>
<body>
<div id ="main">
    <div id ="box">
        <input id="query" type="text" value="" />
    </div>
    <div id ="btn">
        <input id="submit" type="button" value="Search" />
    </div>

</div>
    <div id="tweets">Tweets

    </div>
</body>

</html>

一切正常,但是当它从个人资料图像 url 接收代码时,它只显示 URL 而不是图像本身。我如何获得显示的个人资料图像而不仅仅是代码?

谢谢

4

1 回答 1

1

只需将图像 url 包装在 img 标签中

tweets.append('<div><img src="' + data['results'][res]['profile_image_url'] +'">' + data['results'][res]['from_user'] + ' Said: <p>' + data['results'][res]['text'] + '</p></div><br />');
于 2013-04-11T17:33:58.637 回答