繁体   English   中英

js控制台-SCRIPT5009中的ReferenceError:“ channel_click”未定义

[英]ReferenceError in js console -SCRIPT5009: 'channel_click' is undefined

我在js控制台的IE9中收到“ SCRIPT5009:'channel_click'未定义”错误。 该代码可在chrome和firefox中使用,但是在单击链接以启动IE9中的js序列时突然停止了。

我一直试图解决这个问题,但没有成功,但是我所做的是定时安排一系列事件发生,这些事件包括:

1) onclick - toggle div to hide
2) wait 1500 
3) open print command
- User closes the window to return to page
4) wait 3500 toggle div to show again

我这样做的原因是,当用户决定打印页面时,我不希望打印预览获取这些系列的div。

Javacript:

<script>
//WAITS UNTIL EXCESS IS HIDDEN THEN FIRES PRINT COMMAND 
function channel_click(){

// anon wrapper function, 2 second delay
setTimeout( function () {
window.print();return false;
} , 1500 );

}
</script>


<script>
//HIDES EXCESS IN PREP FOR FIRING PRINT COMMAND PREVIOUS FUNCTION EXECUTES IN BETWEEN FOLLOWING FUNCTIONS
$(".hideshow").click(function () {
$("#header,#footer").toggle("slow");

setTimeout( function () {
$("#header,#footer").toggle("slow");
} , 3500 );
$('.modal-backdrop').hide();
});
</script>

HTML:

<a href="#" role="button" class="hideshow" onclick="channel_click()">Print Preview</a>

<div id="header">
    <div class="pull-left">
    <h1>Edt Mode</h1>
    <h6 style="padding-bottom: 30px;">Some informational text here</h6>
</div>

<div>
    <div class="pull-left">
    <h1>PRINT ME!</h1>
    <h6 style="padding-bottom: 30px;">PRINT ME -  PRINT ME - PRINT ME</h6>
</div>

<div id="footer">
    <div class="pull-left">
    <h1>Edt Mode</h1>
    <h6 style="padding-bottom: 30px;">Some informational text here</h6>
</div>

<div class="model-backdrop">wow this is some more text</div>

您尝试在html中使用它之前,是否加载了javascript文件? 如果这样做,那不是问题,但是如果您不尝试链接到html文件末尾的.js文件。

如果您不希望这样做,则必须将channel_click包装在window.onload中,或者使用jQuery

$(document).ready(function() {
    function channel_click() {
        ....
    }
})

尝试从锚标记中删除onclick:

<a href="#" role="button" class="hideshow">Print Preview</a>

JS:

<script type="text/javascript">
function channel_click(){    
    // anon wrapper function, 2 second delay
    setTimeout( function () {
         window.print();return false;
     } , 1500 );    
 }

    $(document).ready(function() {  //add this
        $(".hideshow").click(function (e) {
            e.preventDefault();
            $("#header,#footer").toggle("slow");
            channel_click(); //call print

           setTimeout( function () {
              $("#header,#footer").toggle("slow");
           } , 3500 );
           $('.modal-backdrop').hide();
         });
    });

在这里它按预期工作

http://jsbin.com/imimom/2

由于您的html格式不正确,因此我看不到任何错误。 也许您可以为我们提供完整的标记?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM