Javascript 如何更改打字稿中的 css 样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46469853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:27:13 来源:igfitidea点击:
How to change css style in typescript?
提问by
In typescript how to change css styling just as I would do this way?
在打字稿中如何像我这样做一样更改 css 样式?
$(".s-hand").css("transform", "translate(-50%, -100%) rotate(" + s*6 + "deg)");
or
或者
var hourPointer = document.querySelector('.hour')
hourPointer.style[transform] = `rotate(${hour}deg)`;
Because I have no idea how to achieve that..
因为我不知道如何实现..
回答by
It has to be done like this:
它必须像这样完成:
let shand = document.getElementsByClassName('s-hand') as HTMLCollectionOf<HTMLElement>;
if (shand.length != 0) {
shand[0].style.transform = "translate(-50%, -100%) rotate(" + s * 6 + "deg)";
}
回答by Nishant Singh
you can do it with simple javascript as mentioned below:
您可以使用简单的 javascript 来完成,如下所述:
document.getElementsByClassName('s-hand').style.transform = 'translate(-50%, -100%) rotate(" + s*6 + "deg)';
for any query please comment
如有任何疑问,请发表评论

