Javascript 触摸事件在模式弹出窗口上不起作用

Javascript 触摸事件在模式弹出窗口上不起作用,javascript,jquery,html,modal-popup,Javascript,Jquery,Html,Modal Popup,我有一个简单和复杂的问题,在触摸事件的模式弹出窗口。在我的弹出窗口中,我显示了一个图像,对于该图像,我正在触发touch事件,但它在某个时间起作用,而不是几乎所有时间都起作用。 第二个问题只出现在模式弹出窗口上:滑动事件根本不会触发。 有什么问题吗? 以下是我在Logcat中收到的警告: 每次接触模态弹出窗口,我都会得到这个 W/webview(5558):从webcore接收到陈旧的触摸事件动作;忽视 对于模式弹出窗口上的滑动,我得到: 11-14 12:42:09.420:W/webview

我有一个简单和复杂的问题,在触摸事件的模式弹出窗口。在我的弹出窗口中,我显示了一个图像,对于该图像,我正在触发touch事件,但它在某个时间起作用,而不是几乎所有时间都起作用。 第二个问题只出现在模式弹出窗口上:滑动事件根本不会触发。 有什么问题吗? 以下是我在Logcat中收到的警告: 每次接触模态弹出窗口,我都会得到这个 W/webview(5558):从webcore接收到陈旧的触摸事件动作;忽视

对于模式弹出窗口上的滑动,我得到: 11-14 12:42:09.420:W/webview(5558):在等待WebCore对着陆的响应时,我们错过了一次拖动

有趣的事情只是在模态弹出窗口中发生,而不是在所有屏幕上。 任何帮助都将不胜感激

下面是我用于模式弹出的javascript代码

var modal = (function() {
var method = {}, $overlay, $modal, $content, $close;

// Center the modal in the viewport
method.center = function() {
    var top, left, position;
    top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
    left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
    $modal.css({
        top : top + $(window).scrollTop(),
        left : left + $(window).scrollLeft()
    });
};   
// Open the modal
method.open = function(settings) {

    $content.empty().append(settings.content);
    $modal.css({
        width : settings.width || 'auto',
        height : settings.height || 'auto'
    });
    method.center();
    $(window).bind('resize.modal', method.center);
    $modal.show();
    $overlay.show();
};   
// Close the modal
method.close = function() {
    // alert("Called close method");
    $modal.hide();
    $overlay.hide();  
    $content.empty();
    $(window).unbind('resize.modal');
};

// Generate the HTML and add it to the document
// $screen = $()
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="#">close</a>');

$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function() {

    $('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );

    function onStart ( touchEvent ) { 

            var flag = confirm("Are you sure want to defuse it?")
                if (flag == true) {                 
                $('#bombImg').attr('src', 'img/undefused.png');

            } else {   
                $('#bombImg').attr('src', 'img/bomb01.png');
            }
     touchEvent.preventDefault();
            modal.close();

      }
}); 

return method;
 }());   

 // Wait until the DOM has loaded before querying the document
//this method calling from another HTML file
 function showDialog(e) {
disableZoomButtons();
$.get('popUp.html', function(data) {
    modal.open({
        content : data
    });   
});
document.ontouchmove = function(e) {
    return false;
}

modal.open({
    content : "<div id='imgDiv'><img id='bombImg' src='img/bomb01.png'/><br>"
        + "</div>"
});

e.preventDefault();     
}     
var modal=(函数(){
var method={},$overlay,$modal,$content,$close;
//在视口中使模态居中
method.center=函数(){
var顶部、左侧、位置;
top=Math.max($(窗口).height()-$modal.outerHeight(),0)/2;
左=数学.max($(窗口).width()-$modal.outerWidth(),0)/2;
$modal.css({
top:top+$(窗口).scrollTop(),
左:左+$(窗口)。滚动左()
});
};   
//打开模型
method.open=函数(设置){
$content.empty().append(settings.content);
$modal.css({
宽度:settings.width | |“自动”,
高度:设置。高度| |“自动”
});
方法。中心();
$(window.bind('resize.model',method.center));
$modal.show();
$overlay.show();
};   
//关闭模式
method.close=函数(){
//警报(“称为关闭方法”);
$modal.hide();
$overlay.hide();
$content.empty();
$(window.unbind('resize.modal');
};
//生成HTML并将其添加到文档中
//$screen=$()
$overlay=$('');
$modal=$('');
$content=$('');
$close=$('');
$modal.hide();
$overlay.hide();
$modal.append($content,$close);
$(文档).ready(函数(){
$('body')。追加($overlay,$modal);
//这里尝试了图像id、div id和modal,但没有效果
document.getElementById(“内容”).addEventListener('touchstart',
函数(e){onStart(e);},false);
函数onStart(touchEvent){
var flag=confirm(“您确定要解除它吗?”)
如果(flag==true){
$('bombImg').attr('src','img/undefuse.png');
}否则{
$('bombImg').attr('src','img/bomb01.png');
}
touchEvent.preventDefault();
modal.close();
}
}); 
返回法;
}());   
//在查询文档之前,请等待DOM已加载
//此方法从另一个HTML文件调用
函数显示对话框(e){
禁用ZoomButtons();
$.get('popUp.html',函数(数据){
模态开放({
内容:数据
});   
});
document.ontouchmove=函数(e){
返回false;
}
模态开放({
内容:“
” + "" }); e、 预防默认值(); }
请任何人帮我解决这个问题。
我在安卓4.0+上运行此应用程序

您必须将
onStart()
函数置于
文档就绪
之外:

function onStart ( touchEvent ) { 

        var flag = confirm("Are you sure want to defuse it?")
            if (flag == true) {                 
            $('#bombImg').attr('src', 'img/undefused.png');

        } else {   
            $('#bombImg').attr('src', 'img/bomb01.png');
        }
 touchEvent.preventDefault();
        modal.close();

  }

$(document).ready(function() {

$('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );
}); 

谢谢你的回复。。在就绪功能外尝试,但仍不工作。