gpt4 book ai didi

javascript - 通过 JavaScript 插入 HTML 时更改文件路径

转载 作者:太空宇宙 更新时间:2023-11-04 14:32:24 25 4
gpt4 key购买 nike

我有一个运行批处理文件的按钮,代码是:

<button onclick="window.open('file:///C:/Users/gthornbu/Desktop/TEST/test.bat')">Continue</button>

我可以将它直接放在 HTML 文件中,它工作得很好,但是我通过 output.innerHTML 将这段特定的代码插入到文件中,但它不起作用。我假设必须更改“/”,但我也尝试过:

<button onclick='window.open('file:///C:\\Users\\gthornbu\\Desktop\\TEST\\test.bat')'>Continue</button>...which also does not work. Any ideas what I'm missing here?

我正在使用的 JavaScript:

function novpn() {
var output = document.getElementById("main");
var sentence = "<h3>You are not connected to the VPN. In order to proceed, you must sign in and launch 'Network Connect'.</h3></br><button onclick='window.open('file:///C:\\Users\\gthornbu\\Desktop\\TEST\\test.bat')'>Continue</button>";

output.innerHTML = sentence;
}

最佳答案

' 嵌套在 ' 中。

最简单的方法是使用 ",但转义为内引号。然后返回到原始 URL(带正斜杠):

var sentence = "<h3>You are not connected to the VPN. In order to proceed, you must sign in and launch 'Network Connect'.</h3></br>" +
"<button onclick='window.open(\"file:///C:/Users/gthornbu/Desktop/TEST/test.bat\")'>Continue</button>";

关于javascript - 通过 JavaScript 插入 HTML 时更改文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32992801/

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