首页 > 解决方案 > Onclick 事件未打开 Bootstrap 模式

问题描述

我正在尝试在单击按钮时打开引导模式,但似乎我的代码没有运行。这是我的代码片段:

<button type="button" class="btn btn-xs btn-default" onclick="openViewUserModal(<?= $users['userid']; ?>); return false;">
  <span class="glyphicon glyphicon-eye-open"></span>
</button>
function openViewUserModal(id) {
  var data = {
    "id": id
  };
  jQuery.ajax({
    url: "includes/viewUser.php",
    method: "POST",
    data: data,
    success: function(data) {
      jQuery('body').append(data);
      jQuery('#viewUserModal').modal({
        backdrop: 'static',
        keyboard: false,
        show: true
      });
    }
  });
}

单击该按钮不会引起响应。我究竟做错了什么?

标签: javascriptphpjqueryhtml

解决方案


这应该有效,标记 echo 语句。我认为这是一个错字。

<button type="button" class="btn btn-xs btn-default" onclick="openViewUserModal('<?php echo $users['userid']; ?>');">
  <span class="glyphicon glyphicon-eye-open"></span>
</button>

推荐阅读