简体   繁体   English

jSignature复制svg信息以形成文本字段

[英]jSignature copy svg information to form text field

I have this script running, the user can place it's signature. 我正在运行此脚本 ,用户可以放置其签名。 But I am not succeeding in getting the svg information that was generated copied to an text field so I can send it with this html form to my database. 但是我无法成功将生成的svg信息复制到文本字段,因此我可以使用此html表单将其发送到我的数据库。

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

<textarea id="signature_svg" rows="5" cols="50"></textarea>

.

<script src="vendor/jsignature/jSignature.min.js"></script>
<script>
    $(document).ready(function() {
        var $sigdiv = $("#signature")

        $sigdiv.jSignature() // inits the jSignature widget.
        // after some doodling...
        $sigdiv.jSignature("reset") // clears the canvas and rerenders the decor on it.

        // Getting signature as SVG and rendering the SVG within the browser. 
        // (!!! inline SVG rendering from IMG element does not work in all browsers !!!)
        // this export plugin returns an array of [mimetype, base64-encoded string of SVG of the signature strokes]
        var datapair = $sigdiv.jSignature("getData", "svgbase64") 
        var i = new Image()
        i.src = "data:" + datapair[0] + "," + datapair[1] 
        $(i).appendTo($("#signature_svg")) // append the image (SVG) to DOM.

        $("#signature").bind('change', function(e){ document.getElementById('signature_svg').value; })
    })
</script>

I am not detecting any errors in my console . 我没有在控制台中检测到任何错误。

Any suggestions how to get the information of signature into signature_svg so I can send the form with this information? 关于如何将signature信息放入signature_svg任何建议,以便我可以将包含此信息的表格发送给我?

Solution is moving a part of the code to an JS event. 解决方案是将部分代码移至JS事件。

<script>
    $(document).ready(function() {
        var $sigdiv = $("#signature")

        $sigdiv.jSignature() // inits the jSignature widget.
        // after some doodling...
        $sigdiv.jSignature("reset") // clears the canvas and rerenders the decor on it.
    })
</script>

<script>
function copy()
{
    // signature
    var $sigdiv = $("#signature")
    var datapair = $sigdiv.jSignature("getData", "svgbase64") 
    document.getElementById("signature_svg").value = datapair[1];
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM