将输入字段设置为包含 window.location.href
Setting Input field to contain window.location.href
如何使用Javascript获取输入字段具有当前网页URL的值?
我建议的方法:
<script>
var holder = window.location.href;
</script>
<input id="moo" value= holder>
要将文本输入字段的值设置为当前页面的位置,首先,我们必须正确设置 HTML:
<input type="text" id="moo">
使用 JavaScript,我们可以通过调用 document.getElementById
来轻松选择此元素,将文本字段的id
作为参数传入:
var input = document.getElementById("moo"); // "moo" is the 'id' of the text field
现在,我们可以将文本字段的value
分配给location.href
:
input.value = location.href;
现在,我们的输入字段将包含当前网页的位置。
var input = document.getElementById("moo"); // "moo" is the 'id' of the text field
input.value = location.href;
<input type="text" id="moo">
HTML
<input type="text" id="url" placeholder="type the url to navigate to" />
<button id="search">
search
</button>
.JS
$(function() {
$("#search").click(function() {
var url = $("#url").val();
window.location.href = url;
});
});
相关文章:
- window.location替换并传递URL历史记录条目中的变量
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- window.location使用jquery mobile实现chrome跳转
- Windows.Open 在 window.Location 工作时不起作用
- 如何将所有作业自定义到window.location.href
- window.location未刷新到现有URL
- 如果window.location.href.indexOf('player=1')添加样式
- 在$state.go之后执行$window.location.reload(true)
- javascript window.location在检查firebug时给了我一个错误的url路径
- angularjs 中 $window.location.reload() 和 $route.reload() 之间的区
- 在AJAX中使用window.location.replace'成功'回调
- IE中不支持JQuery window.location.hash
- PhoneGap如何在更改window.location/document.location后保持Javascript的
- 如何在更改window.location后停止执行
- 警报中的window.location必须重定向到上一页
- 如何在窗体操作或window.location(PHP)中使用数据切换
- 正在将目标添加到window.location
- window.location.htm无法在chrome扩展中工作
- 可以'当window.location.href时,无法从javascript获取post值
- 基于AJAX的网站中的JS window.location