我有一个弹出窗口,使用表单和单选按钮列出图像。
单击单选按钮时,将调用该函数,该函数应传回父窗口。
我继续将'undefined'作为对我来说意味着尚未设置的值。
我如何解决此错误?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!-- Begin
function sendValue (s){
var selvalue = s.value;
//window.opener.document.getElementById('details').value = selvalue;
//window.close();
alert(selvalue);
}
// End -->
</script>
<form name="selectform">
<?php
// Define the full path to your folder from root
$path = "../../images/news/";
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
$myfile = $file;
echo '<input type="radio" name="details" value="'.$myfile.'" onClick="sendValue(this.form.details);" />'.$file.'<br />';
}
// Close
closedir($dir_handle);
?>
</form>
</body>
</html>
答案 0 :(得分:1)
为什么不直接将单选按钮值发送到函数,而不是完整的单选按钮引用:
<强> HTML 强>
<input type="radio" name="details" value="1" onClick="sendValue(this.value);" />
<input type="radio" name="details" value="2" onClick="sendValue(this.value);" />
<强>的Javascript 强>
function sendValue(val){
alert(val);
if(window.opener && !window.opener.closed) {
// do something with the parent window
}
}