不知道如何解释这一点,但我正在尝试打开一个新窗口,同时在打开的页面上设置一个特定的单选按钮。
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)放在同一页面上,它适用于同一页面
然而目前所有的代码都是打开一个新页面!(联系我们.php)
我不是 100% 确定这可以做到,但我的最终目标是打开一个新页面,当用户单击图像时已经选择了单选选项。
PS这不是完整的代码,因为我只发布了我认为相关的部分。