Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中用锚标记包装动态生成的td_Javascript_Jquery - Fatal编程技术网

在javascript中用锚标记包装动态生成的td

在javascript中用锚标记包装动态生成的td,javascript,jquery,Javascript,Jquery,请帮忙!我从外部域获取RSS提要,并使用javascipt为每个项目(标题、日期、链接)生成“s”,现在“link”项目以属性而不是链接的形式出现,那么我如何将此链接作为锚定标记或将其与所需链接相链接? i、 e,我如何用锚定标签包装这些内容 提前谢谢你,我感谢你的帮助 这是我的剧本: for (var i = 0; i < items.length; i++) { var item = items[i]; // Get the title from th

请帮忙!我从外部域获取RSS提要,并使用javascipt为每个项目(标题、日期、链接)生成“s”,现在“link”项目以属性而不是链接的形式出现,那么我如何将此链接作为锚定标记或将其与所需链接相链接? i、 e,我如何用锚定标签包装这些内容

提前谢谢你,我感谢你的帮助

这是我的剧本:

for (var i = 0; i < items.length; i++) {

        var item = items[i];
        // Get the title from the element.  firstChild is the text node containing
        // the title, and nodeValue returns the value of it.
        var title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
        var pubDate = item.getElementsByTagName('pubDate')[0].firstChild.nodeValue;
       var link =item.getElementsByTagName('link')[0].firstChild.nodeValue;//

        //var link ='<a href="' + item.getElementsByTagName('link')[0].firstChild.nodeValue + '">';//


        var table = document.createElement('table');

        var tr = [];

        var td1 = document.createElement('td');
        var td2 = document.createElement('td');
        var td3 = document.createElement('td');



        var text1 = content.appendChild(document.createTextNode(title));
        var text2 = content.appendChild(document.createTextNode(pubDate));
        var text3 = content.appendChild(document.createTextNode(link));



        for (var i2 = 1; i2 < 4; i2++) {
            tr[i2] = document.createElement('tr');
            for (var j = 1; j < 4; j++) {
                td1.appendChild(text1);
                td2.appendChild(text2);
                td3.appendChild(text3);
                tr[i2].appendChild(td1);
                tr[i2].appendChild(td2);
                tr[i2].appendChild(td3);

            }//End of nested FOR
            table.appendChild(tr[i2]);

        } // end of Parent FOR

        tablearea.appendChild(table);
for(变量i=0;i
我认为有更好的方法,比如使用
div
s而不是表,但是在这个问题的限制范围内,是否可以简单地使用与锚定/链接相同的行为?如果可以,也许您可以简单地将此代码添加到循环中

Javascript:

tr[i2].className="link" //class for some UX hints
tr[i2].onclick=(function(link){
  return function(e){
    e.preventDefault();
    location.href=link
  }
})(link)
CSS:

这应该允许用户单击行上的任意位置以跟随链接


你能展示RSS提要吗?如果我正确理解了你的问题,你就不能,因为
a
tr
中不允许的内容。
tr.link {cursor:pointer}
tr.link:hover {background:#FF0}