2013-03-13 102 views
3

将事件“点击”到jquery.mobile中存在问题。当对项目进行“轻击”时,该项目被隐藏,它触发位于该项目下方的INPUT字段上的事件“焦点”。 我该如何让焦点事件不会被解雇? 这是一个小例子代码。jquery.mobile“点击”发射“焦点”事件

<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
    <style> 
    .drop { 
     position: fixed; 
     left: 0; 
     top: 0; 
     width: 100%; 
     z-index: 100; 
     padding: 0 0 1px; 
    } 
    .drop .holder { 
     overflow: hidden; 
     padding: 10px 10px 3px; 
     margin: 0 24px -2px; 
     background: #1c365b; 
    } 
    a {font-size: 24px;} 
    </style> 
</head> 
<body> 
    <form action="#" id="form"> 
    <input type="text" name="input 1"> 
    <input type="text" name="input 2"> 
    <input type="text" name="input 3"> 
    </form> 
    <div class="drop"> 
    <div class="holder"> 
     <a>Link 1</a><br> 
     <a>Link 2</a><br> 
     <a>Link 3</a><br> 
    </div> 
    </div> 
    <div id="console"></div> 
    <script> 
    $(function() { 
     var console = $('#console'); 
     $('.drop').find('a').unbind('tap').bind('tap', function (e) { 
     console.append(' tap on drop menu'); 
     $('.drop').hide(); 
     return false; 
     }); 
     $('#form').find('input').unbind('focus').bind('focus', function (e) { 
     console.append(' focus on ' + $(e.target).attr('name')); 
     }); 
    }); 
    </script> 
</body> 

隐藏下拉后你会得到:

<div id="console">tap on drop menu focus on input 2</div> 

stopImmediatePropagation()方法并不能帮助。

回答

0

在JSFiddle中使用您的确切代码我没有遇到您遇到的问题。 我已经在桌面浏览器和我的S3 Chrome浏览器中试过了。

叠加的div消失并触发轻击事件,但焦点事件不会触发,直到您在叠加消失后选择其中一个输入框为止。

http://jsfiddle.net/U9bYR/

我唯一改变的代码为删除你的事件代码不必要的方法。

$(function() { 
    var console = $('#console'); 
    $('.drop').bind('tap', function (e) { 
    console.append(' tap on drop menu'); 
    $('.drop').hide(); 
    return false; 
    }); 
$('#form').find("input").bind('focus', function (e) { 
    console.append(' focus on ' + $(e.target).attr('name')); 
    }); 
}); 
+0

在Chrome浏览器中的一切似乎不错。我可以在“Mobile Safari”和“Opera Mobi”上重现它。我在使用“Safari”浏览器的项目中使用phonegap。 – Anton 2013-03-14 08:37:40

0

可能的解决方案是,我需要更换上的click事件(jQuery的提供)水龙头事件(提供jquery.mobile)。

0

我有完全相同的问题,我无法找到很好的解决方案。

我想这是移动Safari的一个问题,但你是我发现的第一个跟我有同样问题的人。

临时解决方案是:禁用您想要点击的按钮下方隐藏的所有字段。

在煎茶它看起来像这样:

disableFields: function() { 
    this.enableFieldsFunc(); //lets make sure all fields were switched back to default values 
    this.disableAllFields(); //and then disable them 
}, 
disableAllFields: function() { 
    fields = Ext.ComponentQuery.query('field'); 
    for(var i = 0; i<fields.length; i++) { 
     var field = fields[i]; 
     if(field.getComponent() && field.getComponent().input && field.getComponent().input.dom && field.getComponent().input.dom) { 
      field.wasDisabledBefore = field.getComponent().input.dom.disabled; 
      field.getComponent().input.dom.disabled = true; 
     } 
    } 
}, 
enableFields: function() { 
    Ext.create('Ext.util.DelayedTask', this.enableFieldsFunc, this).delay(100); 
}, 
enableFieldsFunc: function() { 
    fields = Ext.ComponentQuery.query('field'); 
    for(var i = 0; i<fields.length; i++) { 
     var field = fields[i]; 
     var disabled = field.wasDisabledBefore; 
     if(typeof disabled != 'undefined') { 
      field.getComponent().input.dom.disabled = disabled; 
     } 
    } 
} 

而且在按下发布事件,我呼吁disableFieldsenableFields