簡體   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