我想用javascript ipinfo API响应填充输入字段。我准备好填写一个预输入,而不是一个输入。为了保存这些信息,我需要用表格发送它。
请看这里,http://jsfiddle.net/ak2txped/2/
$(window).load(function(){
$.get("http://ipinfo.io", function(response) {
$("#ip").html(response.ip);
$("#code").html(response.country);
$("#address").html("Location: " + response.city + ", " +
response.region);
$("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="details"></pre>
<form id="details" action="/action_page.php" method="post">
Details: <input type="text" name="fname" value="pre"><br>
<input type="submit" value="Submit">
</form>
提前感谢
发布于 2018-06-04 15:09:43
您需要提供输入id
<input type="details" name="details" value="pre" id="fname">
然后使用响应中的JQuery设置值。
$("#fname").val(response.org);
工作环节
http://jsfiddle.net/ak2txped/5/
https://stackoverflow.com/questions/50683386
复制相似问题