繁体   English   中英

jQuery无法通过函数传递变量

[英]Jquery can't pass variable through function

$(document).ready(function() {

//var audit_to_del;
//var type;
//var option_selected;
//var progress;
 function redirect(audit_type) { 
           var page;
                switch(audit_type){
                    case 'Simple 123': 
                          page = 'smeg';
                          break; 
                }//end switch
            return page;
       }

    $('#audit_summary_list_div').on("click", ".go_btn", function(e){ 
         var audit_to_del = $(this).prev('.audit_to_del').val();
         var type = $(this).closest('tr').find('.audit_type').text();
         var option_selected = $(this).closest('td').prev().find('.option_select').val();
         var progress = $(this).closest('tr').find('.progress').text();

         var location = redirect(type);

     alert(location);
   });
});

如果我通过函数传递文字值,它将起作用并返回“ smeg”

var location = redirect('Simple 123');

如果我alert(type)该值正确显示为Simple 123

如果我尝试使用

var location = redirect(type);

我收到未定义的错误

我尝试创建全局变量,然后在函数中使用它们

您的文本中带有空格,使条件为假。 尝试:

var location = redirect($.trim(type));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM