gpt4 book ai didi

javascript - Html-table,使用外部 Google 搜索链接的单元格值,仅适用于一个搜索词

转载 作者:行者123 更新时间:2023-12-03 02:43:57 24 4
gpt4 key购买 nike

我有一个 html 表格,链接如下。在每行最后一个单元格中都有一个 Google 按钮,该按钮可以使用行第一个单元格的值执行 Google 搜索。在新选项卡中打开它。

当第一个单元格中只有一个单词时,这非常有效。当使用多个单词搜索时,例如“alter table”,我收到错误“SyntaxError:未终止的字符串文字”。对此有何建议?

我尝试将innerHTML 替换为textContent 和innerText,但没有用。

http://kajlax.mbnet.fi/Projects/sql/

let table = document.getElementById("sqlTable");
let rows = table.rows;

for (let i = 1; i < table.rows.length -1; i++) {
rows[i].cells[3].innerHTML = "<button target='_blank' onclick=window.open('https://www.google.fi/search?q=sql+"+rows[i].cells[0].innerHTML+"') class='ui primary icon compact mini button'><i class='inverted google icon'></i>";
}

最佳答案

您可以使用此脚本。它会对你有帮助。

for (let i = 1; i < table.rows.length -1; i++) {
str = rows[i].cells[0].innerHTML;
res = str.replace(" ", "+");
rows[i].cells[3].innerHTML = "<button target='_blank' onclick=window.open('https://www.google.fi/search?q=sql+"+res+"') class='ui primary icon compact mini button'><i class='inverted google icon'></i>";
}

关于javascript - Html-table,使用外部 Google 搜索链接的单元格值,仅适用于一个搜索词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48189216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com