使用TypeScript设置window.location [英] Set window.location with TypeScript
本文介绍了使用TypeScript设置window.location的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下TypeScript代码的错误:
I am getting an error with the following TypeScript code:
///<reference path='../../../Shared/typescript/jquery.d.ts' />
///<reference path='../../../Shared/typescript/jqueryStatic.d.ts' />
function accessControls(action: Action) {
$('#logoutLink')
.click(function () {
var $link = $(this);
window.location = $link.attr('data-href');
});
}
我收到以下红色加下划线错误:
I am getting an underlined red error for the following:
$link.attr('data-href');
消息说:
Cannot convert 'string' to 'Location': Type 'String' is missing property 'reload' from type 'Location'
有谁知道这意味着什么?
Does anyone know what this means?
推荐答案
窗口.location
的类型为位置
,而 .attr('data-href')
返回一个字符串,所以你必须将它分配给 window.location.href
,它也是字符串类型。为此替换以下行:
window.location
is of type Location
while .attr('data-href')
returns a string, so you have to assign it to window.location.href
which is of string type too. For that replace your following line:
window.location = $link.attr('data-href');
这个:
window.location.href = $link.attr('data-href');
这篇关于使用TypeScript设置window.location的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文