将value元素设置为window.open()调用的其他页面 [英] Set value element to a other page called by window.open()
问题描述
我正在努力实施此案,非常感谢您的帮助.
I'm struggling to implement this case, I really appreciate your help.
更新:
page1.html
page1.html
<html>
<head>
<title></title>
</head>
<body >
<form>
filled value : <input type="text" id="one">
</form>
</body>
</html>
page2.html
page2.html
<form>
<input type="button" onclick='go();' value='call_page1'/>
</form>
首次尝试:显示第1页,但未设置值
<script>
function go(){
var newWindow;
newWindow= window.open('page1.html', 'form', 'width=400,height=350');
newWindow.document.getElemetById('one').value='xxx';
}
</script>
第二次尝试:甚至没有显示page1
<script>
function go(){
var detailsWindow;
detailsWindow = window.open('page1.html', 'form', 'width=400,height=350');
detailsWindow.onload = function{
document.getElementById('one').value='test';
}
}
<script>
问题:在 page2.html
中调用时,将 value
'的值设置为 page1.html
吗?
Question : setting value
' value to page1.html
, when it's called in page2.html
?
或者如果有其他选择(但是请对我轻松一点,我只是在学习这些东西).我不使用JQuery
,如果有不清楚的地方,我很高兴听到.
Or if there's an alternative (but please take it easy on me, i'm just learning this stuff ). I don't use JQuery
, if there's something unclear, i'm happy to hear it.
谨记.
推荐答案
首先,JavaScript区分大小写,并且缺少 n
.因此,将 getElemetByID
替换为 getElementById
.
First of all javascript is case sensetive, and n
is missing. so replace getElemetByID
with getElementById
.
第二个原因是代码立即执行,并且不等待页面加载.您必须将代码包装在 window.onload
中:
Second is that the code executes immediately and doesn't wait the page to load. You must wrap your code in window.onload
:
newWindow.onload = function(){
newWindow.document.getElementById('one').value='xxx';
}
此更新中存在3个错误:
there's 3 bugs in the update:
- 必须使用
-
function
. - 您的最终脚本必须从
< script>
替换为</script>
- 您在
document.getElementById('one').value ='test';
中丢失了detailsWindow
;它必须为detailsWindow.document.getElementById('一个').value ='test';
detailsWindow.onload = function()
声明 detailsWindow.onload = function
中的function
indetailsWindow.onload = function
must be declared withdetailsWindow.onload = function()
to work.- your end script is must be replaced from
<script>
to</script>
- you are missing
detailsWindow
indocument.getElementById('one').value = 'test';
it must bedetailsWindow.document.getElementById('one').value = 'test';
这篇关于将value元素设置为window.open()调用的其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!