使用jQuery调用函数 [英] Calling the function using jquery

查看:77
本文介绍了使用jQuery调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用此功能

<script>
function getvalue(){
$(document).ready(function(){
    $("[type='radio']").change(function ()
    {
      var hidden = $(this).prevAll("[type='hidden']");
      var h3 = $(this).prevAll("h3");
      hidden.val(h3.text());
      //alert(hidden.val());
    });
  });
}
</script>

发生的事情是,单击任何单选按钮都不会触发该功能..但是单击第二个按钮,我已经使用了document.ready,但是它不起作用..我遗漏了任何一点吗?谢谢:)

what happens is, clicking on any radio button doesnt fire the function.. but clicking on second does, i have already used document.ready but its not working.. any point which i am missing? Thanx :)

推荐答案

删除函数getvalue(){.....或调用函数getvalue.此代码未将事件处理程序注册为就绪",因此不会触发

Remove function getvalue(){..... or you call the function getvalue. This code not register the event handler "ready" and so not fire

 <script>

    $(document).ready(function(){
        $("[type='radio']").change(function ()
        {
          var hidden = $(this).prevAll("[type='hidden']");
          var h3 = $(this).prevAll("h3");
          hidden.val(h3.text());
          //alert(hidden.val());
        });
      });

    </script>

 <script>
       function getvalue(){
        $(document).ready(function(){
            $("[type='radio']").change(function ()
            {
              var hidden = $(this).prevAll("[type='hidden']");
              var h3 = $(this).prevAll("h3");
              hidden.val(h3.text());
              //alert(hidden.val());
            });
          });
       }
        getvalue();
        </script>

这篇关于使用jQuery调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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