0

我从 GitHub 得到了这段代码:

<script src="path/to/jSignature.min.js"></script>

<script>
    $(document).ready(function() {
        $("#signature").jSignature()
    })
</script>

<div id="signature"></div>

但它不会在实际网页上拉出任何东西。我认为需要更多代码,但我不知道从哪里开始。

4

1 回答 1

1

Here is a minimal working example

<!DOCTYPE html>
<html lang="en">
    <head>
        <lang>
        <title>Minimal working jSignature Example</title>
        <meta charset="UTF-8">
        <!-- Files from the origin -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script src="https://willowsystems.github.io/jSignature/js/libs/jSignature.min.js"></script>
    <head>
    <script>
    $(document).ready(function() {
        // Initialize jSignature
        $("#signature").jSignature();
    })
    // ripped from the description at their the Github page
    function getBase64Sig(){
         // get the element where the signature have been put
         var $sigdiv = $("#signature");
         // get a base64 URL for a SVG picture
         var data = $sigdiv.jSignature("getData", "svgbase64");
         // build the image...
         var i = new Image();
         i.src = "data:" + data[0] + "," + data[1];
         // and put it somewhere where the sun shines brightly upon it.
         $(i).appendTo($("#output"));
    }
    </script>
    <body>
        Put your signature here:
        <div id="signature"></div>
        <button onclick="getBase64Sig()">Get Base64</button>
        <div id="output"></div>
    </body>
</html>

I hope you can go on from here.

It is really as simple as they describe it to be, only their description of the actual example is a bit lacking for beginners.

于 2016-04-21T01:31:37.173 回答