JQuery Mobile Custom Theme Buttons

眉间皱痕 提交于 2019-12-02 02:34:58

问题


I just started using a jquery mobile custom theme instead of one of the defaults. Lots of issues...but the current one is that dynamically created buttons don't work as expected.

I have some dynamic html I'm injecting via $("#container").append(...)

            <div>
                <a class="view-it" data-role="button" href="">View</a>
            </div>

Because it's dynamic, I need to do

$("*[data-role='button']").button();

to get it to initialize.

Although my button now looks like a button, the anchor instead still looks like a hyperlink and the click event only fires when clicking on the hyperlink inside the button, not on other areas of the button itself.

Any ideas?

Update:

If I use a div like so instead of an anchor

            <div class="view-it" data-role="button">
                View 
            </div>

It displays correctly now, but still doesn't respond to clicks across the entire button's surface...only around the text (+ a tiny bit of margin)


回答1:


data-role=button is deprecated so you need to add classes manually and it doesn't require any manual enhancement even if you append them dynamically. .button() is used for <input type=button> only.

Your solution is as follows:

var Btn = '<a href="#" class="ui-btn ui-btn-Custom ui-btn-icon-Position ui-icon-Name">Button</a>';

$(".selector").append(Btn);
  • ui-btn-Custom: is theme swatch i.e. ui-btn-a

  • ui-btn-icon-Position: icon's position, left,right,top,bottom or notext i.e. ui-btn-icon-left

  • ui-icon-Name: icon's image i.e. ui-icon-home

Demo



来源:https://stackoverflow.com/questions/22078664/jquery-mobile-custom-theme-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!