按钮点击不在JavaScript中激活

时间:2015-12-31 10:31:22

标签: javascript button click server ready

这是我的代码" btnviewreport1"页面加载后不会触发

<script type="text/javascript">

 $(document).ready(function () {
        var hfDoYouWantPrint = document.getElementById('<%= hfDoYouWantPrint.ClientID %>').value;

        if (hfDoYouWantPrint == 1) {
            var r = confirm("Do you want to print?");
            if (r == true) {
                document.getElementById('<%= btnviewreport1.ClientID %>').click();
            } else {

            }
        }
    });


</script>

1 个答案:

答案 0 :(得分:0)

你必须使用Trigger而不是调用&#39; click()&#39;方法

见下文

&#13;
&#13;
document.getElementById('').trigger('click');
&#13;
&#13;
&#13;

http://api.jquery.com/trigger/