[英]How to dynamically retrieve the value of an input type “url” and put it in a variable?
I have an input of type "url" that has a placeholder. 我有一个带有占位符的“ url”类型输入。
The user has to complete that url. 用户必须完成该URL。
I would like to get the value that the user entered, put it in a variable 我想获取用户输入的值,并将其放入变量中
and then use it in my script. 然后在我的脚本中使用它。
Here is my html 这是我的html
`<input type="url" name="input1" value="https://myWebApplication.com/logs/">`
here is what I tried to do using Jquery but I always get the initial value of the placeholder instead of the newly entered URL. 这是我尝试使用Jquery进行的操作,但是我总是获得占位符的初始值,而不是新输入的URL。
`var newURL = "";
$("input").keyup(function() {
newURL = $(this).val();
}).keyup();`
I'm unable to retrieve the newly inserted value. 我无法检索新插入的值。
try $(this).prop("value")
尝试
$(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/">
Fiddle: http://jsfiddle.net/bLewqzqd/ 小提琴: http : //jsfiddle.net/bLewqzqd/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.