2011-11-29 68 views
0

即时通讯使用jquery片段来将wordpress RSS馈送到我的网站。我是新来的编码,并且把它和一些运气结合在一起。为javascript代码添加一个href类?

我的问题是如何传递href class =“iframe”代码,看起来像这样?

rssoutput+="<li><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></li>" 

谢谢!

<script> 
$(document).ready(function(){ 
     //Examples of how to assign the ColorBox event to elements 
     $(".group1").colorbox({rel:'group1'}); 
     $(".group2").colorbox({rel:'group2', transition:"fade"}); 
     $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"}); 
     $(".group4").colorbox({rel:'group4', slideshow:true}); 
     $(".ajax").colorbox(); 
     $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344}); 
     $(".iframe").colorbox({iframe:true, width:"80%", height:"100%"}); 
     $(".inline").colorbox({inline:true, width:"50%"}); 
     $(".callbacks").colorbox({ 
      onOpen:function(){ alert('onOpen: colorbox is about to open'); }, 
      onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, 
      onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, 
      onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, 
      onClosed:function(){ alert('onClosed: colorbox has completely closed'); } 
     }); 

     //Example of preserving a JavaScript event for inline calls. 
     $("#click").click(function(){ 
      $('#click').css({"background-color":"#fff", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here."); 
      return false; 
     }); 
    }); 
</script> 

回答

3

只是类属性添加到字符串

rssoutput+="<li><a href='" + thefeeds[i].link + "' class='iframe'>" + thefeeds[i].title + "</a></li>" 

编辑

在您的iframe的ID是myFrame

rssoutput += "<li><a href='" + thefeeds[i].link + "' class='iframe' target='myFrame'>" + thefeeds[i].title + "</a></li>" 
+0

嗯。似乎没有工作。但是到达那里。该页面会在iframe之外打开。 iframe在网站的其他区域工作 – user1071890

+0

如果您希望链接的结果页面在同一个iframe中打开,请先为iframe指定一个ID,然后将其定位到链接中。请参阅上面的修改示例。 –

+0

我觉得它的close ..im现在在玩它。 – user1071890

0

学会做更少的“粘性”代码(所有事情都通过字符串操作完成的代码),但是要使用结构化对象。如果你使用jQuery,你也可以使用github.com上的jquery-mochikit-tags项目(发现它作为练习给读者:-))并以编程方式创建html,并使用像这样的appendappendTo这样的jQuery构造:

$.LI(
    $.A(
    {'href': thefeeds[i].link, 'class': 'iframe'}, 
    thefeeds[i].title 
) 
).appendTo('#containerOfRssOutput'); 
+0

谢谢。我看到你在那里做什么,但这超出了我的技能。即时通讯使用其他人写的插件。只是试图让它适合我的网站。 – user1071890

+0

如果你看到我在这里做什么,那么它绝对不会超出你的范围。 :-)你应该试试看。 – 2011-11-29 18:39:19