我有这个剧本运行,用户可以放置它的签名。但是,我没有成功地获得被复制到文本字段中的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>我没有发现我的控制台有任何错误。
有什么建议吗?如何将signature的信息输入signature_svg,这样我就可以用这些信息发送表单了吗?
发布于 2018-10-07 09:07:13
解决方案是将代码的一部分移动到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>https://stackoverflow.com/questions/52680316
复制相似问题