按钮在列表组中不起作用

时间:2018-08-05 11:26:31

标签: javascript jquery html twitter-bootstrap

我在一个弹出框内的列表组中添加了一个按钮,但它根本无法工作。我已经尝试了很多方法,例如摆脱btn类,将ul更改为div并重写其中的所有代码,在js文件中多次重写了click函数,将.click()函数更改为.on( 'click',...)函数,甚至删除了按钮本身,并使列表组项目成为按钮(list-group-item-action),没有任何效果。
如何使此按钮起作用?

JSFiddle:https://jsfiddle.net/rarenex/sqfuk49z/

Dim y As String ‘ being inside the form this is a locally scoped variable
y= Me.Tag ‘ assign “local” y the value stored in Tag property from outside the form
.... ‘ your code
Me.Tag = y ‘ store final value of “local” y to Tag property and make it avalable to the “outer” world


<!--HTML-->
<ul class="list-group list-group-flush">
  <li class="list-group-item cart-order">
    Latte
    <!-- THE BUTTON -->
    <button type="button" class="btn btn-danger delete-order">x</button>
  </li>
</ul>

2 个答案:

答案 0 :(得分:2)

弹出窗口将从页面中删除,并根据需要重新插入。这将导致您添加到页面加载内容中的所有事件侦听器丢失

在按钮上使用event delegation

$(document).on('click','.delete-order',function() {
   alert("YAY");
});

DEMO

答案 1 :(得分:1)

尝试一下:

  $(document).on('click','.delete-order',function(event){
    alert("YAY");
  });