访问变量形式函数时出错
-
22-12-2019 - |
题
在 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
});
});
不隶属于 StackOverflow