0

我正在尝试为从网站获取数据的 chrome 扩展,但无法使链接可点击。我不能在链接中使用 javascript(例如:href="javascript:myfunction(param);")

我需要为每个标题创建一个div,然后创建一个处理div的innerhtml的onclick函数,我无法让它工作。

到目前为止,这是我的代码:

document.addEventListener('DOMContentLoaded', function () {

$().ready(function () {
var url = 'http://somewebsite';

$.get(url, function (data) {
data = data.split("<tr name=\"hover\">");





var name;
var link;

var count = data.length;
count++;
for(var i = 1; i < data.length; i++){
    data[i] = data[i].replace("<br>","<br />");
    data[i] = data[i].replace("class=\"thread_link\"", "");
    data[i] = data[i].replace("<td class=\"forum_thread_post\" align=\"center\">0</td>","");
    data[i] = data[i].replace("<td class=\"forum_thread_post\">","");
    data[i] = data[i].replace("</td>","");
    data[i] = data[i].replace('<td class="forum_thread_post" align="center">0</td>','');
    if(i != data.length-1){
        data[i] = data[i].replace("<a href=\"", "");
        data[i] = data[i].replace("</a>", "");
        data[i] = data[i].split("\" >");
        data[i][1] = data[i][1].split("<");
        document.write('<div id="' + data[i][1][0] + '">' + data[i][1][0] + data[i][0] + "</div><br /><br />");

    }else{
        data[i] = data[i].split("</table>")[0];
        data[i] = data[i].replace("<a href=\"", "");
        data[i] = data[i].replace("</a>", "");
        data[i] = data[i].split("\" >");
        data[i][1] = data[i][1].split("<");
        document.write('<div id="' + data[i][1][0] + '">' + data[i][1][0] + data[i][0] + "</div>");

    }

}
//document.body.innerHTML = '';


//console.log(data);
 });
 });
});

document.write('</script>');
function getshow(url){
alert(url);
document.body.innerHTML = '';
$.get("http://somewebsite" + url, function (dat) {
    document.write(dat);
});
}
4

0 回答 0