我有一個隱藏的字段,應該從一個div中獲取字符串值,並且在瀏覽器中工作時都很好,但是當我運行它時它不起作用平板電腦或智能手機。我不明白這一點。Javascript設置隱藏的字段值不在移動設備上工作
,這裏是我的div和隱藏字段:
div id="signature-div" style="border: dotted 2px grey;">
<div id="canvas"></div>
</div>
<input name="signature" type="hidden" id="signature" value="">
和功能:
$(document).ready(function() {
// signature
var W = $("#signature-div").width();
var sigCanvas = $("#canvas").jSignature({width: W, height: 180, "background-color":"#ddd"});
// after signing the offer set hidden field value to signature
$(document).on('mouseup', '#canvas',function(){
//$("form").submit(function() {
var rawSig = $("#canvas").jSignature("getData","svg");
//$("#img").attr("data", 'data:' + rawSig);
//$("#signature").val('data:' + rawSig);
document.getElementById("signature").value = 'data:' + rawSig;
// i have tried both of these up and it doesn't set the hidden value on mobile devices...is there something i'm missing here?
});
});
你做它'mouseup' ...片和智能手機沒有鼠標。試着將'touchend'事件添加到你的腳本中...像這樣:'$(document).on('mouseup touchend','#canvas',function(){' –
你是對的,只是做出答案出來它,我會接受它 – lewis4u