javascript - 在 javascript 代码中添加 href 类?

标签 javascript

我正在使用 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>

最佳答案

只需将类属性添加到字符串

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>"

关于javascript - 在 javascript 代码中添加 href 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8315446/

相关文章:

javascript - Node/ express : Error: Failed to lookup view "error" in views directory

javascript - 使用其他对象的键查找对象中的键/值

javascript - 如何使用 JS/jQuery 将 HTML 元素的 ID 设置为等于其内部文本?

javascript - 在没有 OOP 结构的 JS 中创建对象

javascript - 在悬停时使用 html 和 javascript 让子 dom 元素超出父 div 的范围

javascript - 使用 Bootstrap 动态填充下拉菜单

javascript - 如何通过具有特定选定值的选择返回 div 中的表?

javascript - 点击 : Passing String as Parameter

javascript - 如何在 teaspoon-Jasmine 测试中包含脚本标签

javascript - 如何从黑莓手机访问 Google Analytics?