我有一个问题,我想我知道答案。
使用action =“mailto:function。
,使用一些html代码我的问题是,我是否可以根据以下代码中的选择将主题分配给生成的电子邮件?例如。主题:紧急;选择紧急时。
<head>
<title></title>
</head>
<body>
<form enctype="text/plain" method="post" id="orderform" action="mailto:randomeemail@gmail.com?subject" >
<table border="1" align="left" style="width: 100%">
<tbody>`enter code here`
<tr>
<td style="text-align: justify;"><label for="element_10" class="Deliverys">What
Type of Delivery is required?</label></td>
<td style="text-align: justify;">
<select name="Urgency Required">
<option value="Standard">Standard Delivery</option>
<option value="Fast">Fast</option>
<option value="Urgent">Urgent</option>
<option value="Required in 4 hours">Required in 4 hours</option>
<option value="Required in 2 hours">Required in 2 hours</option>
<option value="Pick-up">Pick-up</option>
</select>
</td>
</tr>
<input type="submit" value="Submit" name="Submit" />
</form>
</body>
</html>
答案 0 :(得分:0)
如果您不介意使用Javascript,可以执行以下操作:
<script>
function myFunction(){
window.location.href = 'mailto:randomeemail@gmail.com?subject=' + document.querySelector('select[name="Urgency Required"]').value
return false
}
</script>
<form enctype="text/plain" method="post" id="orderform" onsubmit="return myFunction();" >
<table border="1" align="left" style="width: 100%">
<tbody>`enter code here`
<tr>
<td style="text-align: justify;"><label for="element_10" class="Deliverys">What
Type of Delivery is required?</label></td>
<td style="text-align: justify;">
<select name="Urgency Required">
<option value="Standard">Standard Delivery</option>
<option value="Fast">Fast</option>
<option value="Urgent">Urgent</option>
<option value="Required in 4 hours">Required in 4 hours</option>
<option value="Required in 2 hours">Required in 2 hours</option>
<option value="Pick-up">Pick-up</option>
</select>
</td>
</tr>
<input type="submit" value="Submit" name="Submit"></input>
</tbody>
</table>
</form>
基本上,当表单提交时,它会动态生成mailto链接,然后打开它。然后它返回false,这会阻止表单实际提交(即重定向到操作)。