代码之家  ›  专栏  ›  技术社区  ›  lewis4u

Javascript从另一个不在移动设备上工作的字段设置隐藏字段值

  •  0
  • lewis4u  · 技术社区  · 9 年前

    我有一个隐藏字段,它应该从div中获取字符串值,在浏览器中工作时一切都很好,但在平板电脑或智能手机上运行时却不起作用。我不明白。

    这是我的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?
    
        });
    
    });
    
    2 回复  |  直到 9 年前
        1
  •  1
  •   Louys Patrice Bessette    9 年前

    在上执行“获取字符串值” mouseup ...

    平板电脑和智能手机没有鼠标。
    尝试添加 touchend 事件添加到脚本…如下所示:

    $(document).on('mouseup touchend', '#canvas',function(){
    

    同时检查另一个 touch events .
    ;)

        2
  •  1
  •   Edward D    9 年前

    没有鼠标的设备永远不会触发“mouseup”事件

    还添加“touchend”事件:

    $(document).on('mouseup touchend', '#canvas',function(){
    ...