2014-07-10 163 views
1

HTML:的Javascript打印格内容

<div id="printDiv" class="table-responsive"> 

     @Html.Raw(Model.Content) 

    </div> 

<button type="button" onclick="Print()">Print</button> 

的Javascript:

function Print() { 
     alert("working"); 
     $("#printDiv").printThis(); 
    } 

当我点击打印按钮,我想打印DIV content.However如果我点击按钮,我得到下面的JavaScript代码异常。

Uncaught TypeError: undefined is not a function 

我不知道我在哪里错过了?

任何帮助将不胜感激。 谢谢。

+0

下载js文件可能会请你帮忙的感谢 –

回答

3

尝试添加printThis.js。

从下面的链接

https://github.com/jasonday/printThis

示例代码

<!DOCTYPE html> 
    <html> 
    <head> 
<script src="assets/js/jquery-1.9.1.js"></script> 
<script src="assets/js/printThis.js"></script> 
<style> 
     .drag 
    { 
     width: 100px; 
     height: 100px; 
     background-color: #000; 
    } 

    #box 
    { 
     width: 500px; 
     height: 400px; 
     background-color:red; 
    } 
</style> 
</head> 

<body> 

    <div id="box"> 
     <div id="drag">aaaaaaaaaaaaaaaaa</div> 
    </div> 

    <script> 
     $("#drag").printThis() 
    </script> 


</body> 

</html> 
+0

这工作得很好。想知道为什么这个人接受这个答案留下了这个投票。无论如何,我正在投票。 –