javascript - 如何获取确认按钮值模式

标签 javascript jquery html

假设有一个 html 页面,当我点击一个按钮时,我读到:"

enter image description here

当我点击“确定”按钮时我需要处理

那是html代码:

     <div class="modal-content">
<div class="modal-body">
<button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
<div class="bootbox-body">Are you sure you wish to discard this post?</div></div><div class="modal-footer"><button data-bb-handler="cancel" type="button" class="btn btn-default">Cancel</button><button data-bb-handler="confirm" type="button" class="btn btn-primary">OK</button></div></div>

这是我的 jquery 代码:

(function() {

        $(document).on('click','button[data-bb-handler="confirm"][type="button"]',function(){
            console.log("MAREEEEEEEEEEEEEEEEE "+$(this).length);
        });

}());

这是行不通的。任何人都可以帮助我吗?其他方法?

最佳答案

你可以像这样直接处理事件:

<button id="confirmBtn" type="button" class="btn btn-primary">OK</button>

(function() {

   $("#confirmBtn").click(function(e){
       e.preventDefault();
       console.log("This " + $(this).length);
   })

}());

关于javascript - 如何获取确认按钮值模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39588565/

相关文章:

javascript - 防止 iFrame 更改位置?

javascript - 是否可以在 Ext JS 中执行动态更改forceFit 的函数?

javascript - 从 Facebook 获取点赞

php - 如何从选择框中选择多个选项

javascript - 如何解决Google Charts loader.js只能加载一次

javascript - 如果不直接传递给requestAnimationFrame,函数体不会执行

javascript - jQuery:在更改另一个 css 属性之前等待 css 动画完成

php - MySQL自主重复删除

javascript - 用一个滚动条控制两个 HTML 表格

jQuery Drag - 将一个 div 绑定(bind)到可拖动的 div