哪个库和jquery适合这个代码

which library and jquery suitable for this code?

本文关键字:代码 jquery      更新时间:2023-09-26

我有一些代码在html2canvas。在代码中,jquery是合适的,我试图使html2canvas.js文件插入注释,但$符号没有定义。在记事本没有输出结果。如何获取下载pdf&png图像的get结果?

$(document).ready(function() {
  var element = $("#html-content-holder"); // global variable
  var getCanvas; // global variable
  html2canvas(element, {
    onrendered: function(canvas) {
      getCanvas = canvas;
    }
  });
  var specialElementHandlers = {
    '#editor': function(element, renderer) {
      return true;
    }
  };
  $("#cmd").on('click', function() {
    var imgageData = getCanvas.toDataURL("image/png");
    // Now browser starts downloading it instead of just showing it
    var newData = imgageData.replace(/^data:image'/png/, "data:application/octet-stream");
    $("#cmd").attr("download", "Sample_Pic.png").attr("href", newData);
    var doc = new jsPDF();
    doc.fromHTML($('#target').html(), 15, 15, {
      'width': 170,
      'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
  });
});
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="shot.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>

<link rel="stylesheet" type="text/css" href="shot.css">
</head>
<body>
  <div id="html-content-holder" style="background-color: #FFFFFF; width: 500px;
        padding-left: 25px; padding-top: 10px;">
    <div id="target">
      <div id="content">
        <h3>Hello, this is mathit app</h3>
        <a class="upload">Upload to Formulas</a>
        <h2>
                        This is <b>10th Std Notes</b> <span style="color: red"></span>
                    </h2>
        <p>Study about The polynomial of degree two is called quadratic polynomial and equation corresponding to a quadratic polynomial P(x) is called a quadratic equation in variable x. Thus, P(x) = ax2 + bx + c =0, R is known as the standard form of quadratic
          equation. There are two types of quadratic equation. (i) Complete quadratic equation : The equation ax2 + bx + c =0 where a,b,c is not equal to 0. (ii) Pure quadratic equation : An equation in the form of ax2 = 0, a is not equal to 0, b,c is
          equal to 0.</p>
      </div>
    </div>
  </div>
  <a id="cmd" href="#" class="button">generate PDF</a>
  <br/>
  
</body>
</html>

$符号没有定义,因为您忘记包含jQuery库。将库包含在head标签中。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

这是一个链接到他们的cdn列表