js console -SCRIPT5009中的ReferenceError:'channel_click'未定义

时间:2013-01-25 10:53:14

标签: javascript jquery html

我在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>

4 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

尝试从您的锚标记中删除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();
         });
    });

答案 2 :(得分:0)

这里按预期工作

http://jsbin.com/imimom/2

答案 3 :(得分:0)

由于你的html格式不正确,我没有看到错误。也许你可以为我们提供完整的标记?