【问题标题】:jQuery button not displaying properlyjQuery 按钮无法正确显示
【发布时间】:2013-04-03 10:58:26
【问题描述】:

我在我的应用程序中使用 jQuery 按钮,但由于某种原因,它显示为没有 jQuery 属性的普通按钮。 html 标记位于名为ajax.php 的单独文件中,而 jQuery 位于主文件中。

这里是 jQuery 的代码:

$(".back_to_list").button().live("click", function(){
});

这是按钮的 html 标记:

    $html = '';
    $html .= '<table>
                <tr>
                    <td><button class="back_to_list" >Back</button></td>
                </tr>
            </table>';

echo $html;

有谁知道为什么按钮不显示为 jQuery ui 按钮?

【问题讨论】:

  • .button() 来自jQueryUI,它不属于jQuery Core
  • 请注意,.live()在 1.7 中已弃用,并在 1.9 JQuery 版本中删除
  • @Vucko,这已被注意到,1.7 版正在用于此特定应用程序
  • 你在 jquery lib 下有 jQuery ui 插件吗?
  • 我在其他地方使用过 jQuery 按钮,它们都可以工作,但由于某种原因,这个按钮保持不变

标签: php jquery html jquery-ui


【解决方案1】:

您必须确保在加载文档时调用 .button() 代码(如在第一个示例中):

$(function () { // jQuery "wrapper" for 'run when document is loaded
    $(".back_to_list").button().live("click", function(){
    });
});

编辑:还要注意 .live() 在 jQuery 1.7 中已被弃用,并在 jQuery 1.9 中被删除 使用 .on()。如果您运行的是较新版本的 jQuery,这也可能是您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    相关资源
    最近更新 更多