选中复选框,下载文件,更改文本并提交

时间:2015-09-18 14:20:33

标签: javascript jquery html checkbox

我有一个复选框' JSFiddle'当用户在其中一个复选框上打勾时,它会打开一个新窗口,使用户可以在单击复选框按钮后查看下载PDF。然后禁用下载功能,这样当用户再次勾选复选框按钮时,它会激活提交按钮。

我遇到的问题是当用户点击terms-block div中的任何内容时,下载PDF。最初用户点击文字'条款和条件时我想要的是什么?它会打开PDF,一旦PDF打开,文本就会变为“我同意这些条款”。激活提交按钮......可以这样做

 <div class="terms-block">
    <input type="checkbox" id="terms-agreed" class="form-terms" name="agreed" value="terms">
  <label class="terms-view" for="terms">I agree to the terms and conditions</label>
 </div>

$(function() {
      var checkboxes = $("#terms-agreed"),
      submitButt = $("input[type='submit']");
      enableSub(submitButt );
      checkboxes.on("click",function() {
        enableSub(submitButt );
        if (this.checked) window.open('{site_url}downloads/resellers/Standard_Terms_and_Conditions.pdf');
    });
});

1 个答案:

答案 0 :(得分:1)

你应该做这样的事情:

  • 添加带有文字的标签&#34;条款和条件&#34;有一些id
  • 在一个带有css设置为显示的类的div中:none将复选框和标签放在&#34;我同意条款和条件&#34;。
    • 当用户点击&#34时,将属性已禁用的按钮设置为true;我同意(...)&#34;文本此按钮将更改为启用。

代码可能如下所示:

&#13;
&#13;
 $(function() {
     $("#btnDownload").attr("disabled",true);
     $("#terms_and_conditions").on("click",function(){ 		/*window.open('{site_url}downloads/resellers/Standard_Terms_and_Conditions.pdf');*/
     $("#div_agree").show();
     });
     $("#terms-agreed").on("click",function(){
         if($(this).prop("checked"))
             $("#btnDownload").attr("disabled",false);
         else
             $("#btnDownload").attr("disabled",true);
     });
    });
&#13;
.terms_link{
    cursor:pointer;
}
#div_agree{
    display:none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h1>Button should be enabled if at least one checkbox is checked</h1>

<div class="terms-block">
    <label id="terms_and_conditions" class="terms_link">Click to see terms and conditions</label><br/>
    <div id="div_agree">
                                    <input type="checkbox" id="terms-agreed" class="form-terms" name="agreed" value="terms">
                                    <label class="terms-view" for="terms">I agree to the terms and conditions</label>
                                </div>        
                                </div>
    <br/>
    <button type="button" id="btnDownload">Download</button>
&#13;
&#13;
&#13;

只需调整你的琐事

我评论了window.open行。

希望它对你有所帮助。