Javascript 访问变量形式函数时出错
在chrome函数中,但在IE10中,函数中的变量名返回错误,如何从函数中访问此变量Javascript 访问变量形式函数时出错,javascript,jquery,internet-explorer,internet-explorer-10,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) {
$('.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);
});
});
尝试:
请参见您的错误是什么?等等,您正在尝试使用
href
的值作为jQuery选择器?我正在使用jQuery UI选项卡,在href中有目标div的值。另外,哪个变量<代码>id?我在更改的行中添加了注释。他使用的是$(name).html(result),但应该试试$(name).attr('href',result)啊,谢谢。错过了。注意@Andy的评论:这里的$(名称)
是什么?现在怎么样?我还更改了变量名,因为他将url设置为id值,id设置为href(url)值。现在它只是name->id,以及一个新的var元素,以后用作选择器,而不是旧的$(name)。
$('.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
});
});