我写了小页面,但在这段代码中我有错误。我想使用这种方式,因为 Isotope 不会从 HTML 标签中的样式中读取宽度和高度。
var winw = $(window).width();
var plmt_w = winw / 10;
var plmt_h = plmt_w;
var css = '.plmt { width:' plmt_w '; height:' plmt_h ';}',
.....
最佳答案
正如 ajm 和 Amit Joki 所说,您需要 + 运算符来连接字符串。
但是,由于 $(window).width()
返回一个无单位值,您需要添加 'px' 以使其成为有效的 css 字符串:
var css = '.plmt { width:' + plmt_w + 'px; height:' + plmt_h + 'px;}',
关于javascript - 带有 CSS 的 JS 中的意外字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24121213/