0
我正在尝试在文本框中粘贴路径并单击文件读取按钮时读取文件。问题在于它没有读取 - 但是对于带有文件选项的输入标签,它正在读取。从文本框中读取文件时未在输入标记中输入文件类型
你们能告诉我如何实现它吗?在下面提供我的代码。
https://codepen.io/texirv/pen/dzwrqM?editors=1111
<input class="laptop" placeholder="Paste link here to upload document." type="text" name="sportsBox" id="sportsBox">
$("#swimmingLink").click(function() {
console.log("inside click function--->");
playerValue = $("#sportsBox").val().replace(/\\/g,"/");
var coffee = playerValue.substring(playerValue.lastIndexOf('/')+1)
console.log("playerValue--->" + playerValue);
console.log("coffee--->" + coffee);
//var myReader: FileReader = new FileReader();
var myReader = new FileReader();
//var textType = /text.*/;
var file = playerValue.files[0];
console.log("file---->" + file);
onpaste事件。 https://www.w3schools.com/jsreF/event_onpaste.asp。你正试图在错误的时刻阅读价值。 – PedroSouki
@PedroSouki嘿我试过了,但无法实现在粘贴上使用...你能在我的小提琴更新 –
网页无法以这种方式读取文件。它只能访问用户通过文件输入明确选择的文件,或者从文件浏览器拖放到浏览器上。 –