0
<div id="myLuckyPost">
</div>
<script type="text/javascript"> 
    function showLucky(root){ 
        var feed = root.feed; 
        var entries = feed.entry || []; 
        var entry = feed.entry[0]; 
        for (var j = 0; j < entry.link.length; ++j){
            if (entry.link[j].rel == 'alternate'){
                window.location = entry.link[j].href;
            }
        }
    } 
    function fetchLuck(luck){ 
        script = document.createElement('script'); 
        script.src = '/feeds/posts/summary?start-index='+luck+'&max-results=1&alt=json-in-script&callback=showLucky'; 
        script.type = 'text/javascript'; 
        document.getElementsByTagName('head')[0].appendChild(script); 
    } 
    function feelingLucky(root){ 
        var feed = root.feed; 
        var total = parseInt(feed.openSearch$totalResults.$t,10); 
        var luckyNumber = Math.floor(Math.random()*total);
        luckyNumber++; 
        a = document.createElement('a'); 
        a.href = '#random'; 
        a.rel = luckyNumber; 
        a.onclick = function(){
            fetchLuck(this.rel);
        }; 
        a.innerHTML = 'View Random Post';
        document.getElementById('myLuckyPost').appendChild(a); 
    } 
</script> 
<script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script>

这会生成一个随机博客帖子的链接。现在我想将“查看随机帖子”( a.innerHTML = 'View Random Post';) 文本链接更改为图像。是否可以?

4

1 回答 1

0

这是你想要的?

a.innerHTML = "<img src='button.gif' />";
于 2012-06-09T23:24:35.260 回答