如何添加样式到.attr('style','width:newWidth'); 其中newWidth是动态的

Kar*_*way -1 html javascript jquery

我有一个如下代码

var newWidth = Math.floor(width * .75) + 'px';
$(this).find("input:first").attr('style', 'width:newWidth ');
Run Code Online (Sandbox Code Playgroud)

你可以请你纠正我,因为正确的语法是直接传递newWidth不起作用我也必须通过样式才能这样做

tym*_*eJV 5

使用 .css()

$(this).find("input:first").css('width', newWidth);
Run Code Online (Sandbox Code Playgroud)