问题描述
我正在做一个移动应用程序的PhoneGap和jQuery Mobile的。每次我选择菜单元素我打电话给一个WS,让我说,我在显示屏幕的答案之一。它完美地达到那里。
至于我想有更好的视野,所以我用code触发('创造')。 ( http://jquerymobile.com/demos/1.0a4。 1 /文档/表格/表单checkboxes.html 但insted的刷新我不得不作出一个创建)
VAR listadohtml ='< DIV数据角色=fieldcontain><字段集数据角色=controlgroup>';
对于(VAR I = 0; I< resultado.length;我++){
VAR项='';
VAR ID = resultado [I] ['身份证'];
项目+ ='<输入类型=复选框名称=复选框 - '+ ID +'ID =复选框 - '+ ID +'级=自定义/>';
项目+ ='<标签=复选框 - '+ ID +'>'+ resultado [I] [标题] +'< /标签>';
listadohtml + =项目;
}
listadohtml + ='< /字段集>< / DIV>';
$('#LISTA preguntas)HTML(listadohtml).trigger(创造)。
Inmediatly之后,我关联的事件:
$(#LISTA preguntas输入[类型=复选框])。绑定(点击,功能(事件,UI){...一些$ C $Ç...});
这表明一切正常,但问题是,有时(并不总是,这就是问题所在),当我点击绿色的勾不显示一个复选框,但事件更改。当它发生时,我可以看到,通过点击屏幕的其他部分,因为它刷新,并显示打勾,我之前单击。
我有conclussions
- 这不是AVD由于IM让我的手机所有的测试与Android 4.0。
- 看来,它的东西的code,包括jQuery Mobile的,当我使用去触发。
- 我想是不是加载时间,因为我可以等待几年,它可以发生。
正如你可以看到它不是一个逻辑的问题,而是一个可用性的。
在此先感谢!
有关选和单选,使用变更
事件不是点击
。而且要记住,附加活动,以动感的元素不同的是,我已经相应地更新我的答案。
$(文件)。在('变','[类型=复选框]',函数(){ // code在这里});
I'm making a mobile application with phonegap and jquery mobile. Everytime I select one of the menu elements I call to a WS that gives me an answer that I show in the screen. It works perfectly up to there.
As I want to have a better view so I use the code trigger ('create'). (http://jquerymobile.com/demos/1.0a4.1/docs/forms/forms-checkboxes.html but insted of refresh I have to make an create)
var listadohtml = '<div data-role="fieldcontain"><fieldset data-role="controlgroup">';
for (var i=0;i<resultado.length;i++){
var item = '';
var id = resultado[i]['id'];
item += '<input type="checkbox" name="checkbox-'+id+'" id="checkbox-'+id+'" class="custom" />';
item += '<label for="checkbox-'+id+'">'+resultado[i]["title"]+'</label>';
listadohtml += item;
}
listadohtml += '</fieldset></div>';
$('#listaPreguntas').html(listadohtml).trigger('create');
Inmediatly after that I associate an event:
$("#listaPreguntas input[type='checkbox']").bind( "click", function(event, ui) {... some code ...});
It shows everything fine, but the problem is that sometimes (not always, that's the problem) when I click a checkbox the green tick is not shown but the event change is made. When it happens I can see, by clicking in other part of the screen, that I have clicked before because it refreshes and shows the tick.
The conclussions I have
- It is not the AVD because im making all the tests in my mobile phone with android 4.0.
- It appears that its something of the code that includes jquery mobile when I use de trigger.
- I think it is not loading time because I can wait for years and it can happens.
As you can see its not a "logic" problem but a usability one.
Thanks in advance!
For checkbox and radio, use change
event not click
. And keep in mind that attaching events to dynamic elements is different, I have updated my answer accordingly.
$(document).on('change', '[type=checkbox]', function () {
// code here
});
这篇关于单击事件作出,但它不会在屏幕上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!