javascript - 根据复制到剪贴板的用户输入生成链接
问题描述
我正在为员工创建一个表格,用于生成链接。我们的网站处理付款。这个想法是工作人员可以输入 23 美元作为 23.00,它将带用户到example.com/pay/23.00
当前按下“获取链接”按钮会将用户带到付款地址。
<script>
function process()
{
var url="http://example.com/pay/" + document.getElementById("url").value;
location.href=url;
return false;
}
</script>
<script>
function myFunction() {
var copyText = document.getElementById("url");
copyText.select();
document.execCommand("copy");
alert("Copied the URL: " + copyText.value);
}
</script>
<form onSubmit="return process();">
<p>Enter the amount as a decimal:</p><br>
<input type="text" name="url" id="url"> <input type="submit" value="Get Link" id="paylink">
</form>
按get link
应该复制 URL 而不是重定向。
任何帮助将不胜感激,因为我快到了。
解决方案
<script>
function process()
{
var url="http://example.com/pay/" + document.getElementById("url").value;
document.getElementById("url").value = url;
var copyText = document.getElementById("url");
copyText.select();
document.execCommand("copy");
alert("Copied the URL: " + copyText.value);
return false;
}
</script>
<p>Enter the amount as a decimal:</p><br>
<input type="text" name="url" id="url"> <input type="button" onclick="process()" value="Get Link" id="paylink">
此外,您应该进行一些验证。
推荐阅读
- powershell - 如何通过powershell以同样的方式获取所有Azure服务的key
- testrail - 在测试铁路中面临 409 问题
- node.js - 带有 URL 参数的请求
- biztalk - BizTalk Server 2016 可以检索终止的消息吗?
- python - 如何使用 GDB 在 C 级调试 python 脚本。给我一个简单的例子
- php - 通过引用传递参数时出现致命错误
- javascript - 添加角框以突出显示(typed.js)
- regex - Excel VBA - 从剪贴板返回字符串中所有子字符串的位置
- javascript - 编辑文本而不影响列中的内容
- node.js - NodeJS泄漏套接字文件描述符