【问题标题】:Button not working using javascript [closed]按钮无法使用 javascript [关闭]
【发布时间】:2013-11-13 10:42:56
【问题描述】:

我使用 javascript 添加了 html 代码。除按钮外,所有标题和 div 都可以正常工作。该按钮未添加或由于某些原因可能无法正常工作。请检查我的代码给出一些建议。当我使用与 html 相同的代码时,它运行良好。

var ItemsToAdd = '';
ItemsToAdd += '<h5 style="margin-top:10px; margin-left:10px; font-size:30px;" >' + app.categories[0].name + '</h5>\
                       <div><img src="' + app.info_icon_path + '" style="margin-top:10px; margin-left:10px; float:left;"  alt="Info_image"/></div>\
                       <div > <a data-role="button"  style="margin-top:135px; margin-left:5px; width:136px; height:50px; float:left;">Load</a></div>\
                       <div>\
                            <h5 style="margin-top:10px; margin-left:10px;font-size:30px;" >' + app.name + '</h5>\
                            <p style="margin-left:10px; margin-right:20px">' + app.desc_short + '<br></br></p>\
                        </div>\
                        <div class="ui-block-d"> <a data-role="button"  style="margin-top:0px; margin-left:5px; width:136px; height:50px; float:left;">more info</a>\
                        </div>\
                        <p><br><br><br></p>\
                        <h5 style="margin-top:30px; margin-left:10px;font-size:20px;" >Version ' + app.version + '</h5>\
                        <h5 style="margin-top:10px; margin-left:10px;font-size:20px;" >' + app.price + '</h5>';

$("#content2").append(ItemsToAdd);

【问题讨论】:

  • 你能做一个 JsFiddle 吗?
  • 你在用按钮做什么。也许你的事件没有附加。

标签: javascript jquery html jquery-mobile button


【解决方案1】:

尝试使用更新的库 JQuerymobile。并且需要刷新动态添加的 HTML 元素。

终于用上了

$("#content2").trigger('create');

【讨论】:

  • 谢谢哥们......它只需添加 $("#content2").trigger('create'); $("#content2").append(ItemsToAdd); 之后
  • @naki $("#content2").append(ItemsToAdd).trigger("create");
【解决方案2】:

使用不能直接在移动jquery中添加动态html你需要在jquery mobile中使用“刷新”或者使用.button()方法来实现jquery mobile UI的动态外观...

http://jquerymobile.com/demos/1.2.0/docs/buttons/buttons-methods.html

你可以看这里http://www.gajotres.net/jquery-mobile-and-how-to-enhance-the-markup-of-dynamically-added-content/了解更多详情

  $("#addbutton2_here").append('<a data-role="button">' + getTime() + '</a>');
  $("#addbutton2_here").find("a[data-role='button']").button();

这是FIDDLE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多