首页 > 解决方案 > 如果选中收音机,则显示消息操作

问题描述

我有一个 HTML 输入单选

<input class="payment_processor_gocardless crm-form-radio" value="5" type="radio" id="QFID_5_payment_processor_id" name="payment_processor_id">

通常不选择收音机。我想做的是,每当我点击那个收音机时,我都希望通过 sweetalert 显示一条消息。这是我的代码:

$('input[name=payment_processor_id]”]’).click(function()  {
    if (($("input[name=payment_processor_id]").attr("value")=="5") ) {  
          Swal.fire({
sweetalert message goes here
        });
  }
});

Sweetalert 在其他领域也很实用,所以这不是我关心的问题。选择单选按钮时我无法触发它。任何帮助,将不胜感激。谢谢

标签: jqueryradio-buttonsweetalert2

解决方案


你在做一些语义错误,在你的代码中做了修改。

$('input[name="payment_processor_id"]').click(function()  {
    if (($('input[name="payment_processor_id"]').attr("value")=="5") ) {  
          Swal.fire({
              sweetalert message goes here
        });
  }
});

推荐阅读