无法在java脚本弹出窗口中检索文本框值
Cannot retrieve text box value in java script popup
我想将parent.php中的文本框值传递到我的弹出窗口(child_page.php)。以下是我的代码。parent.php-
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open()
{
popupWindow =window.open('child_page.php',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
<input type="text" name="myTextField" id="myTextField" required="required"/>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<a href="javascript:child_open()">Click me</a>
</body>
</html>
child_page.php
<h1>child page</h1>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
var x=parent.document.getElementById('myTextField').value
<?php echo x; ?>
</script>
<?php
//how do I get the textbox value here.
?>
我在谷歌上搜索了一下,并试着这么做。由于我对java脚本知之甚少,所以无法将这些答案作为一个解决方案。
您的html中有很多错误。在关闭head标记之前,您正在编写输入元素。把它移到身体内部。试试这样的东西:
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open(val){
popupWindow =window.open('child_page.php' + "?val=" + val,"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<input type="text" name="myTextField" id="myTextField" required="required"/>
<a href="#" onclick="var val = document.getElementById('myTextField').value; child_open(val);return false">Click me</a>
</body>
</html>
现在,在您的child_page.php
中,您可以使用$_GET['val']
获取值。
//child_page.php
<h1>child page</h1>
<?php $x = $_GET['val']; ?>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
<?php echo $x; ?>
相关文章:
- 本地存储保存和检索文本输入值
- 在按键时检索文本区域的 ID
- 单击按钮后从jQuery检索文本到HTML
- 如何在 html CDATA 部分中检索文本
- 如何使用jquery从输入复选框中检索文本
- 创建一个bookmarklet,可以检索文本框的所有最大长度,然后在表中打印id和最大长度
- 如何使用$scope和ng-bind在AngularJS中检索文本框条目
- JQuery 检索文本而不是选择列表的值
- 使用正则表达式 Javascript 检索文本的父节点
- 从段落中检索文本并更改其颜色
- 将鼠标悬停在文本上时检索文本值
- 无法在java脚本弹出窗口中检索文本框值
- 通过Webdriver从JavaScript警报中检索文本
- 如何在Angular中使用相同的ng-model从多个输入字段中检索文本
- 我如何使用JavaScript从不同的网站检索文本
- 从元素中检索文本并将其插入到其他地方
- 脚本-检索文本输入
- 如何使用casperjs从嵌入式脚本检索文本?
- 如何从选定的href标记内的span标记检索文本?
- 如何检索"文本"用CasperJS中的JavaScript从文档中提取