在div上调用.jSignature()不会更新div

时间:2016-04-20 23:45:58

标签: javascript html jsignature

我从GitHub获得了这段代码:

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

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

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

但它并没有在实际的网页上提升任何东西。我认为需要更多代码,但我不知道从哪里开始。

1 个答案:

答案 0 :(得分:1)

这是一个最小的工作示例

<!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>

我希望你能从这里继续。

它实际上就像它们描述的一样简单,只有他们对实际例子的描述对初学者来说有点缺乏。