gpt4 book ai didi

Javascript - window.location.assign 不工作

转载 作者:行者123 更新时间:2023-11-29 19:31:59 24 4
gpt4 key购买 nike

我有一个项目,我在其中扫描二维码,然后它会根据扫描的二维码自动打印出信息。

我有扫描仪和打印机。每个二维码对应一个URL。我可以让扫描仪填写一个输入字段,我可以得到一个警报来显示扫描的信息。但是,每当我尝试分配 URL 时,它只是将信息附加到当前 URL,而不是替换它。

我需要它来替换当前的 URL。有谁知道它为什么这样做,以及如何解决它?

<html>
<head><title>QR Printing</title></head>

<body onload="document.myform.mytextfield.focus();">

<form name="myform">
<input type="text" name="mytextfield" onchange="checkForm()">
</form>

<script type="text/javascript" language="JavaScript">

function checkForm() {
var field1 = document.forms['myform'].elements['mytextfield'].value;
alert(field1);
window.location.assign(field1);
}

</script>

</body>
</html>

最佳答案

看起来表单正在提交。取消它。

<form name="myform" onsubmit="return false">

关于Javascript - window.location.assign 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26936947/

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