我试图让以下工作,但由于某种原因它不是,我似乎不明白为什么。我想要做的是当有人在表单中选择一个选项时,它将下载 url 应用于按钮。
<form class="form-horizontal">
<select class="relationship" id="Relationship">
<option>Select Form</option>
<option>for me</option>
<option>for another</option>
</select>
<a class="btn btn-large btn-primary download" href="#">
<i class="icon-download"></i> Download Form</a>
</form>
<script type="text/javascript">
$(function(){
$(".relationship").change(function(){
if( $(this).val() == "for me" ) {
$("a.download").click(function() {
location.href = 'form1.pdf';
})}
else if ($(this).val() == "for another") {
$("a.download").click(function() {
location.href = 'form2.pdf';
})}
});
});
</script>