如何动态检索输入类型"url"把它放到一个变量里

How to dynamically retrieve the value of an input type "url" and put it in a variable?

本文关键字:quot 变量 一个 url 输入 检索 类型 动态 何动态      更新时间:2023-09-26

我有一个类型为"url"的输入,它有一个占位符。

用户必须填写url。

我想获取用户输入的值,将其放入变量

,然后在我的脚本中使用。

这是我的html

`<input type="url" name="input1" value="https://myWebApplication.com/logs/">`

这是我尝试使用Jquery做的,但我总是得到占位符的初始值,而不是新输入的URL。

`var newURL = "";
 $("input").keyup(function() {
    newURL = $(this).val();
 }).keyup();`

我无法检索新插入的值。

try $(this).prop("value")

$("input").on("keyup", function() {
    alert($(this).prop("value"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="url" name="input1" value="https://myWebApplication.com/logs/">

小提琴:http://jsfiddle.net/bLewqzqd/