htmlchor元素下载在Typescript中不工作
HTMLAnchor element download not working in Typescript
我无法让htmlchor元素的下载属性在TypeScript下工作。我使用下面的代码:
var element = document.createElement('a');
element.href = 'data:attachment/csv,' + encodeURIComponent(csvContent);
element.target = '_blank';
element.mimeType = "attachment/csv";
element.download = 'Report.csv'; /* #debug 030314 this line fails */
document.body.appendChild(element);
element.click();
似乎TypeScript不支持download属性。是否有一种解决方案,将。csv后缀添加到文件中?-是否有可能绕过TypeScript直接调用Javascript代码?
您可以轻松地自己添加:
// Tell TypeScript about it
interface HTMLAnchorElement{
download:string;
}
var element = document.createElement('a');
element.href = 'data:attachment/csv,' + encodeURIComponent(csvContent);
element.target = '_blank';
element.mimeType = "attachment/csv";
element.download = 'Report.csv'; /* No error on this line anymore */
document.body.appendChild(element);
element.click();
download
属性还没有被广泛接受,所以他们还没有实现它。
您总是可以退回到完全支持的setAttribute
:
element.setAttribute("download", "Report.csv");
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- Foreach无法在Typescript中工作
- 如何让jQuery在我的Typescript文件中工作
- 让typescript与facebook登录为Angular 2项目工作
- 调用Typescript setter don't返回函数,尽管关联的getter可以工作
- Web Storm 9.0.3 typescript文件观察程序不工作
- Typescript$inject$timeout到指令中..在控制器中工作,而不是在链接中
- 缩小后,具有typescript的角度筛选器无法工作
- Typescript -w(手表)不工作在我的安装
- TypeScript -使用knockout.js的JavaScript在IE8中无法工作- Object不支持此属性或
- VS Code智能感知javascript不工作,如果我正在编辑typescript
- React typescript类型不能工作
- 使用atom-typescript插件,.js文件中的代码补全是否可以工作?
- 让TypeScript、Karma、RequireJS和Chai一起工作
- TypeScript接口没有像我预期的那样工作
- typescript window.setInterval()工作不正常
- mongodb与typescript ' toArray '方法不工作
- htmlchor元素下载在Typescript中不工作