gpt4 book ai didi

javascript在asp.net mvc中打印div内容

转载 作者:行者123 更新时间:2023-11-30 12:40:25 24 4
gpt4 key购买 nike

HTML:

 <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 内容。但是,如果我点击“打印”按钮,我会得到下面的 javascript 代码异常。

Uncaught TypeError: undefined is not a function 

我不知道我到底错过了什么?

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

最佳答案

尝试添加 printThis.js。

从下面的链接下载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>

关于javascript在asp.net mvc中打印div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24670692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com