douyi9787
2017-07-25 00:33 阅读 96

在.php文件中添加javascript签名板

I have a .php file that once a transaction is approved, I want it to show the signature pad but how will I implement it into my php code. The code below is a part of the .php file and I need to get https://github.com/szimek/signature_pad this signature pad to show but it is in JavaScript.

 if($tran->result == "Approved"){

}

d

if($tran->result == "Approved"){
?>



<?
echo '<canvas id="signature-pad" class="signature-pad" width=400 
height=200></canvas>
    <div>
<button id="save">Save</button>

<button id="clear">Clear</button>
</div>'

?>
 <script type="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/signature_pad/1.5.3/signature_pad.min.js"></script> <script> var signaturePad = new 
 SignaturePad(document.getElementById('signature-pad'), {
  backgroundColor: 'rgba(255, 255, 255, 0)',
  penColor: 'rgb(0, 0, 0)'
});
var saveButton = document.getElementById('save');
var cancelButton = document.getElementById('clear');

saveButton.addEventListener('click', function (event) {
  var data = signaturePad.toDataURL('image/png');

// Send data to server instead...
  window.open(data);
});

cancelButton.addEventListener('click', function (event) {
  signaturePad.clear();
});    </script> </script><script src="touchpadjs.js"></script>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douzhanshen0657 douzhanshen0657 2017-07-26 03:05

    Found out what was wrong, the js file was not being accessed by the html and css code so i just added all the code into the php function as with for javascript and for css and it all started working.

    点赞 评论 复制链接分享
  • doutucui0133 doutucui0133 2017-07-25 00:37

    you output the HTML code snippet echo '<canvas id="signature-pad" class="signature-pad" width=400 height=200></canvas>' once approved. You can include JS files in your webpage already or you can include it under above code as <script type="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/signature_pad/1.5.3/signature_pad.min.js"></script> followed by your own JS code <script src="Path_to_your_own_JS_file"></script>

    Example code is already present on the same link at the bottom:

    https://jsfiddle.net/szimek/d6a78gwq/

    点赞 评论 复制链接分享

相关推荐