在 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);
        });
  });
有帮助吗?

解决方案

尝试:

 $('.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
        });
  });

在运行时设置 href 属性

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top