向javascript代码中添加一个href类
adding a href class to javascript code?
我使用一个jquery片段来拉入wordpress rss提要到我的网站。我是编码新手,很幸运地完成了这个程序。
我的问题是我怎么能传递一个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>
只需将class属性添加到字符串
rssoutput+="<li><a href='" + thefeeds[i].link + "' class='iframe'>" + thefeeds[i].title + "</a></li>"
编辑
如果iframe的ID是myFramerssoutput += "<li><a href='" + thefeeds[i].link + "' class='iframe' target='myFrame'>" + thefeeds[i].title + "</a></li>"
学习编写较少的"字符串"代码(所有代码都是通过字符串操作完成的),而是使用结构化对象。如果你使用jQuery,你也可以使用github.com上的jQuery -mochikit-tags项目(发现它留给读者作为练习:-)),以编程方式创建html,并使用jQuery结构,如append
或appendTo
,如下所示:
$.LI(
$.A(
{'href': thefeeds[i].link, 'class': 'iframe'},
thefeeds[i].title
)
).appendTo('#containerOfRssOutput');
相关文章:
- CSS 在悬停时使图像变暗 - 在其周围添加一个 href
- 使用 Javascript 在运行时禁用<一个 href>
- 如何从一个 HREF 填充多个输入字段
- 将现有单选按钮更改为 <一个 href>
- 如何使用 JavaScript 单击一个 href 后编辑 3 个标签的值
- 返回值从 Javascript 到 HTML <一个 href> 标记
- 与号(&)在 DOM 中不转义会生成一个 href
- 使用php变量+javascript变量创建一个href-url
- <一个 href=#> 重定向到索引的链接..php
- 使文件输入成为一个href
- 带有javascript递增url的下一个/上一个href按钮
- 在 Echo 语句中插入一个 href
- 用jquery在一个href值的末尾添加
- 如何防止默认和禁用一个href
- 一个href click或onclick 2个动作(两个或更多函数)
- 如何循环遍历一个href's列表
- 如何通过jquery .html创建一个href,然后使用它的事件
- 向javascript代码中添加一个href类
- 选择一个href="#"打开父母李
- 如何使一个链接记住它的价值作为一个href之前转移到下一页中使用