我正在尝试为我们的实验室工程师构建一个简单的网页,因此当他们坐在他们的工作站时,他们可以从他们的桌面打开网页快捷方式>选择他们所在的实验室>选择他们需要哪种支持>然后单击“提交”以打开包含所有选定信息的电子邮件>然后点击发送;然后向电子邮件列表中的人发送电子邮件请求。
Chrome中的一切都很棒,但我们大多数工程师默认使用IE,当我点击IE中的提交按钮时,它会打开电子邮件,但是To:和Subject:读取“UNDEFINED”。我正在使用IE10。
<!DOCTYPE HTML>
<html>
<link rel="stylesheet" type="text/css" href="silsupport.css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>SILSupport</title>
<body>
<h1>SIL Support</h1>
<SCRIPT>
function e_mail(e_add,subject1,body)
{
window.location="mailto:"+e_add+"?subject="+subject1+"&body="+body;
}
</SCRIPT>
<form name="e_form" enctype="text/plain">
<div id="para1">
<p>Please select which lab you are in: </p>
<input name="subj" type="radio" value="Lab_1 Support" />Lab 1<br />
<input name="subj" type="radio" value="Lab_2 Support" />Lab 2<br />
<input name="subj" type="radio" value="Lab_3 Support" />Lab 3<br />
<input name="subj" type="radio" value="Lab_4 Support" />Lab 4<br />
<input name="subj" type="radio" value="Lab_5 Support" />Lab 5<br />
</div>
<div id="para2">
<p>Please select which support you require:</p>
<input name="emadd" type="radio" value="re@abc.com" />RE Support<br />
<input name="emadd" type="radio" value="admin@abc.com" />Admin Support<br />
<input name="emadd" type="radio" value="system@abc.com" />System Support<br />
<input name="emadd" type="radio" value="hwsw@abc.com" />H/W & S/W Support<br />
<input name="body" type="hidden" value="I require support now!" />
</div>
<input type="button" id="Submit" Value="Submit" onClick="e_mail(this.form.emadd.value,this.form.subj.value,this.form.body.value)" />
</form>
</body>
</html>
答案 0 :(得分:0)
您真的应该拥有自己的代码来查找已选中的单选按钮:
function findChecked(radios) {
for (var i = 0; i < radios.length && !radios[i].checked; ++i);
return radios[i] && radios[i].value;
}
该函数需要一个列表,这是您从单选按钮组引用的内容。它查找选中的按钮并返回其值。
然后:
<input type="button" id="Submit" Value="Submit"
onClick="e_mail(findChecked(this.form.emadd),findChecked(this.form.subj),this.form.body.value)" />
答案 1 :(得分:0)
我相信您遇到的问题是由于您的网址中的字符编码造成的。 将代码更改为此代码以转义空格和感叹号等字符:
window.location="mailto:"+ encodeURIComponent(e_add) +"?subject="+ encodeURIComponent(subject1) +"&body="+ encodeURIComponent(body);
答案 2 :(得分:0)
以下是我要做的事情,因为IE中可能不支持单个无线电值 也逃离实验室的空间。请注意我将表单名称更改为id,将按钮更改为实际提交
最后,您可以在下拉列表中添加size =“5”和=“4”以显示所有选项
window.onload=function() {
document.getElementById("e_form").onsubmit=function() {
var e_add = this.emadd.value,
subject1=this.subj.value,
body=this.body.value,
loc="mailto:"+e_add+"?subject="+encodeURIComponent(subject1)+"&body="+body;
window.location=loc;
return false; // cancel submit
}
}
<form id="e_form" enctype="text/plain">
<div id="para1">
<p>Please select which lab you are in: </p>
<select name="subj">
<option value="Lab_1 Support">Lab 1</option>
<option value="Lab_2 Support">Lab 2</option>
<option value="Lab_3 Support">Lab 3</option>
<option value="Lab_4 Support">Lab 4</option>
<option value="Lab_5 Support">Lab 5</option>
</select>
</div>
<div id="para2">
<p>Please select which support you require:</p>
<select name="emadd">
<option value="re@abc.com">RE Support</option>
<option value="admin@abc.com">Admin Support</option>
<option value="system@abc.com">System Support</option>
<option value="hwsw@abc.com">H/W & S/W Support</option>
</select>
<input name="body" type="hidden" value="I require support now!" />
</div>
<input type="submit" Value="Send" />
</form>