只有当用户选中复选框并提交表单时,我才希望下载 PDF。现在只要他们选中复选框并点击提交按钮,PDF 就会下载。表单是否提交并不重要。主要问题是我仅限于 Jquery 或纯 javascript。我无权访问后端文件。有人知道怎么做吗?不需要该复选框。这是我现在拥有的代码:
$("#formid").submit(function(ev){
ev.preventDefault();
$.ajax({
url: 'processing.cfc', // background processing procedures
type: 'get',
dataType: 'json',
data: $("#formid input, #formid select").serialize(), //pass all present input variables
success: formReturn,
failure: function(){ alert("There was an error processing your request. \nPlease try again."); return false; }
});
var $choice = $(this).find("input[name='checkbox1']:checked");//get the selected option
if ($choice.length)// if an option is selected
window.open('http://whitepaper.com/info/whitepaper/WhyBuy_WhitePaper_FinalB.pdf') ;
var $choice2 = $(this).find("input[name='checkbox2']:checked");//get the selected option
if ($choice2.length)// if an option is selected
window.open('http://brochure.com/info/brochure/welcome-kit-brochure.pdf') ;
});
这是复选框的 HTML:
<div class="chkbox">
<input type="checkbox" class="regular-checkbox" name="checkbox1"
id="checkbox-1-1"><label for="checkbox-1-1"></label>
<span class="dld">Clayton Homes guide to buying a home</span>
</div>
<div class="chkbox">
<input type="checkbox" class="regular-checkbox" name="checkbox2"
id="checkbox-1-2"><label for="checkbox-1-2"></label>
<span class="dld">Why Clayton Homes brochure</span>
</div>
任何帮助表示赞赏。