将表单元格数据转换为单独.js文件中的内部链接

Converting table cells data to internal links in a separate .js file

本文关键字:文件 内部 链接 js 单独 单元格 表单 数据 转换      更新时间:2023-09-26

遇到一个小项目的问题,我在过去的3天里一直被困。。。我必须使用javascript&jquery在一个单独的js文件中由于问题的限制,我无法编辑html文件

我希望我能正确理解你的问题。您可以使用选择器.code访问单元格,然后使用append()在其中放置链接,如下所示:

$(".code").each(function(i){ //find the right cells and for each one...
    var text = $(this).text(); //...read the contents...
    text = text.substring(3); //...remove the first 3 letters...
    $(this).text(""); //...remove the text...
    $(this).append("<a href='"+text+".html'>"+text+"</a>"); //...and replace with a link
});

示例:http://jsfiddle.net/7fawbkck/2/