gpt4 book ai didi

javascript - 如何让 onchange 设置 onclick=window.open(url)?

转载 作者:行者123 更新时间:2023-11-30 12:26:57 27 4
gpt4 key购买 nike

我在 GAS html 服务中有一个应用程序,它有一个文件选择框,旁边有一个按钮,用于在新选项卡中打开它们。我不知道如何完成它。列表中的文件以 google-drive-file-id 形式获取它们的值(假设 fileID1-3 没问题),并且我有一个用于获取整个链接的服务器脚本。这是如何完成的:

HTML:

<select id='fileBox' name='fileBox' onchange="google.script.run.withSuccessHandler(gotFileLink).getFileLinkById(this.value)">
<option value=fileID1>File1.pdf</option>
<option value=fileID2>File2.pdf</option>
<option value=fileID2>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />

服务器代码:

function getFileLinkById(fileID) { return DriveApp.getFileById(fileID).getUrl(); }

客户端代码:

function gotFileLink(url) {
document.getElementById('linkButton').onclick = // what goes here?
}

我尝试了几个使用“window.open”的选项,但不知道如何让它工作。提前致谢。

最佳答案

这是可以帮助您在单击按钮时打开所需链接的代码。

这是一个工作链接: JSFIDDLE

<select id='fileBox' name='fileBox'>
<option value='http://www.google.com'>File1.pdf</option>
<option value='http://www.google.com'>File2.pdf</option>
<option value='http://www.google.com'>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />


var btn = document.getElementById('linkButton');
btn.addEventListener('click',GetInfo,false);

function GetInfo(){
var e = document.getElementById("fileBox");
var selectedUrl = e.options[e.selectedIndex].value;
window.open(selectedUrl);
}

关于javascript - 如何让 onchange 设置 onclick=window.open(url)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29045928/

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