点击列表中的项目内的按钮列表视图有什么方法来创建jQuery Mobile的列表视图具有可点击列表项和每个项目都有3个按钮?我不想使用拆分按钮listview。我试图创建这个,但按钮点击不起作用。点击任何按钮的行为就像点击列表项一样。如何创建与jQuery Mobile的
0
A
回答
1
您可以将e.stopImmediatePropagation();
(http://api.jquery.com/event.stopimmediatepropagation/)添加到按钮点击,以便它们不会传播到父列表项。
更新:在listItems中是动态生成的评论提到
OP。原始代码仍然有效,因为按钮使用了事件代表(https://learn.jquery.com/events/event-delegation/)。下面是一个更新的例子:
空UL标记中
<ul data-role="listview" id="thelist">
</ul>
在pagecreate,填写列表视图,并添加单击处理
$(document).on("pagecreate", "#page1", function(){
//make list dynamically
var allItems = '';
for (var i=0; i< 4; i++){
allItems += '<li data-rowid="' + i + '"><a href="#"><div data-role="controlgroup" data-type="horizontal"><input type="button" value="Hmm" /><input type="button" value="No" /><input type="button" value="Yes" /></div> Item ' + i + ' text or description</a></li>';
}
$("#thelist").empty().append(allItems).listview("refresh").enhanceWithin();
$("#thelist").on("click", "li input", function(e){
e.stopImmediatePropagation();
var rowid = $(this).parents("li").data("rowid");
var btnText = $(this).val();
alert("You clicked the button: " + btnText + " on row number: " + rowid);
});
$("#thelist").on("click", "li a", function(e){
alert("You clicked the listitem");
});
});
更新DEMO
ORIGINAL:
<ul data-role="listview" id="thelist">
<li data-rowid="1">
<a href="#">
<div data-role="controlgroup" data-type="horizontal">
<input type="button" value="Hmm" />
<input type="button" value="No" />
<input type="button" value="Yes" />
</div>
Item 1 text or description
</a>
</li>
</ul>
$(document).on("pagecreate", "#page1", function(){
$("#thelist li").on("click", "input", function(e){
e.stopImmediatePropagation();
var rowid = $(this).parents("li").data("rowid");
var btnText = $(this).val();
alert("You clicked the button: " + btnText + " on row number: " + rowid);
});
$("#thelist li").on("click", "a", function(e){
alert("You clicked the listitem");
});
});
你也可以把按钮列表项锚标记之外并使用CSS来定位的一切好听......
相关问题
- 1. 如何创建一个jQuery Mobile主题
- 2. 如何从JavaScript创建jQuery Mobile按钮?
- 3. 如何创建jQuery Mobile Popup Alert机制?
- 4. 触发创建jQuery Mobile的
- 5. jQuery Mobile的触发创建
- 6. jQuery Mobile创建面板
- 7. jQuery Mobile创建按钮
- 8. 风格JQuery创建与JQuery Mobile CSS的按钮?
- 9. 如何创建与jQuery
- 10. 与jQuery Mobile的
- 11. 如何使用jQuery函数创建jQuery Mobile页面幻灯片?
- 12. 页面创建PhoneGap的jQuery Mobile的
- 13. jQuery Mobile的GridView中动态创建
- 14. 如何动态创建jQuery Mobile中动态创建的可折叠集合
- 15. 如何用jQuery Mobile创建适当的多页结构?
- 16. 如何用jquery mobile创建100%高度的div?
- 17. jQuery Mobile的:如何创建自定义页面过渡
- 18. 如何创建一个超过五列jQuery Mobile的网格?
- 19. 如何增强动态创建的Jquery Mobile复选框?
- 20. jQuery Mobile的:如何创建带有标题和描述
- 21. 如何在使用jQuery Mobile的TelerikMVC3中创建
- 22. 创建与jQuery Mobile的动态表单元素
- 23. 与JQuery Mobile的URL
- 24. AngularJS与jQuery Mobile的
- 25. 创建与jQuery
- 26. Angular.js与jQuery Mobile
- 27. OpenLayers与jQuery Mobile
- 28. 与jQuery Mobile的jQuery委托
- 29. 在jquery mobile中创建会话变量
- 30. jquery mobile通过jsonp创建页面
这JQM版本你正在用吗? – Omar