如何在JQuery中检测按钮值的变化? [英] How to detect button value change in JQuery?

查看:38
本文介绍了如何在JQuery中检测按钮值的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表单,其中包含带有立即获得访问!"值的提交按钮.:

I've a sign up form which has submit button with value "GET INSTANT ACCESS!" :

<input type="submit" class="wf-button" name="submit" value="GET INSTANT ACCESS!">

提交后,该值将更改为谢谢!":

After submit, the value gets change to 'Thank You!':

<input type="button" class="wf-button" value="Thank You!">

我需要检测按钮值.如果它变成谢谢!"然后我必须显示一个弹出窗口.并且此值通过某些Ajax(GetResponse表单)进行更改.没有页面刷新.

I need to detect the button value. If it becomes "Thanks You!" then I have to show a popup. And this value gets change by some Ajax (GetResponse form). There is no page refresh.

我尝试了以下代码,但仅在FireFox&在Chrome中无法使用.

I've tried below code but it is only working in FireFox & not working in Chrome.

<script>
    $(function() {
        $(".modalbox").fancybox();
    });
    $(function() {
        $('.wf-button').bind("DOMSubtreeModified",function(){
            //if btn valu is 'Thank You! trigger popup'                    
            $(".modalbox").trigger('click');

        });
    });
</script> 

实时网址: http://www.idynbiz.com/web/html/gold_ira_vf/?(仅显示按钮如何更改其值)

Live URL: http://www.idynbiz.com/web/html/gold_ira_vf/? (just to show how the button changes its value)

有人可以帮助我如何检测按钮值并显示我的弹出窗口吗?该按钮实时更改其值(Ajax).没有页面刷新.

Can some one help how can I detect the button value and show my popup? The button change its value in real time (Ajax). There is not page refresh.

有没有使用bind()或on()函数的JQuery方法来检测值?

Is there any JQuery approach with bind() Or on() function to detect the value?

推荐答案

$(function() {
  $('.btn1').on('change', function() {
    alert('Do stuff...');
  });
  $('.lnk1').on('click', function() {
    $('.btn1').val('Thank you!');
    $('.btn1').trigger('change');
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="submit" class="btn1" value="SUBSCRIBE" />
<a href="#" class="lnk1">Change button value</a>

这篇关于如何在JQuery中检测按钮值的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆