错误访问变量表单函数

时间:2014-07-31 15:49:06

标签: javascript jquery internet-explorer internet-explorer-10

在chrome函数中,但在IE10中函数中变量名的返回错误,我怎么能从函数中访问这个变量?

  $('.kpit').on('click', function() {        
        var url = $(this).attr('id');
        var name = $(this).attr('href');
        $('.kpi').html('');
        $.post(url, {idKpi: id}, function(result) {
            $(name).html(result);
        });
  });

1 个答案:

答案 0 :(得分:1)

尝试:

 $('.kpit').on('click', function() {        
        var name = $(this).attr('id');
        var element = $(this); //Removed the .attr('href'), as that would store the URL, not the element.

        $('.kpi').html('');
        $.post(name, {idKpi: id}, function(result) {

        $(element).attr('href',result); //Set the HREF by using .attr, not .html
        });
  });

请参阅Setting href attribute at runtime