在IE 11中获取未定义的javascript函数 [英] Get undefined javascript function in IE 11

查看:716
本文介绍了在IE 11中获取未定义的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE 11中调用函数时出现一些错误.对于我来说,我在<script>标签中有两个脚本.

I got some error when call function in IE 11. In my case I have two scripts inside one <script> tag.

这是我的功能:

<script>
function test()
{
    alert("oke");
    var currency = $('#curr_drop').val();
    var total_room_qty = calculate_amount(currency); // total all room

    var btn_class = $('#book_button').prop('class');

    var this_qty = $(this).val();
    var this_plan_type = $(this).data('plan-type');
    var this_plan_id = $(this).data('plan-id');
    var this_plan_day = $(this).data('plan-day');
}

function calculate_amount(currency = 'IDR') 
{
    //alert("ok");
    var nights = $('[name="nights"]').val();
    var total_amount = 0; var total_room_qty = 0; var total_qty_room_id = 0;

    console.log('nights: '+nights);


    return total_room_qty;
}
</script>

我从这段代码中调用test函数:

I call that test function from this code :

<select name="qty" class="mb10" onchange="test.bind(this)()" data-plan-type="rate" data-plan-id="38" data-plan-day="52459">
   <option value="0">0 rooms</option>
   <option value="1">1 rooms</option>
   <option value="2">2 rooms</option>
   <option value="3">3 rooms</option>
   <option value="4">4 rooms</option>
   <option value="5">5 rooms</option>
</select>

我的问题是,当我尝试在功能test顶部显示alert时,我得到了undefined function test,但是如果关闭var total_room_qty = calculate_amount(currency); // total all room,则可以在IE 11浏览器中显示警报.这怎么可能发生,我该如何解决?谢谢

My problem is when I tried to show alert in top of function test I got undefined function test but if I close var total_room_qty = calculate_amount(currency); // total all room the alert can be shown in IE 11 browser. How it could be happen and how to I fix this ? Thanks

推荐答案

calculate_amount的函数声明错误.您正在尝试在ie11中使用es6.

The function declaration for calculate_amount is wrong. You are trying to use es6 in ie11.

function calculate_amount(currency = 'IDR') // this will work only in chrome and firefox 

不幸的是,IE没有引发错误.这就是您的事件处理程序无法访问的原因.

Unfortunately IE didn't throw an error. That is the reason your event handler is not reachable.

将其更改为

function calculate_amount(currency) 
{
    currency = currency || 'IDR'; //if your intent is to set a default value for currency
    //alert("ok");
    var nights = $('[name="nights"]').val();
    var total_amount = 0; var total_room_qty = 0; var total_qty_room_id = 0;

    console.log('nights: '+nights);


    return total_room_qty;
}

示例 https://jsfiddle.net/karthick6891/0681reux/

这篇关于在IE 11中获取未定义的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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