【发布时间】:2011-11-10 16:02:36
【问题描述】:
不知道如何解释,但我正在尝试打开一个新窗口,同时在打开的页面上设置一个特定的单选按钮。
Contact-us.php(我要打开的页面)
<form name="f2" method="post" action="send_form_email3.php" id="Homeform1" onsubmit="return checkEmail(this)">
<input type="radio" name="package" value="Option1"> Basic
<input type="radio" name="package" value="Option2"> Silver
<input type="radio" name="package" value="Option3"> Gold
<input type="radio" name="package" value="Custom"> Custom
这是带有按钮的页面
主页.php
<a href="javascript:win1=window.open('contact-us.php'); setCheckedValue(win1.document.forms['f2'].elements['package'], 'Option2');" id="link2" class="links"></a>
这是JS文件
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}
所以它适用于同一页面,如果我将表单与按钮 (home.php) 放在同一页面上
然而目前所有的代码都是打开一个新页面!(Contact-us.php)
我不能 100% 确定这可以做到,但我的最终目标是打开一个新页面,并在用户单击图像时选择单选选项。
P.S 这不是完整的代码,因为我只发布了我认为相关的部分。
【问题讨论】:
-
您的代码可以与模态 div 或浮动 div 一起使用,那怎么样呢?无论如何,大多数浏览器都会阻止弹出窗口。
标签: javascript html button radio checked