我有这段代码来检索某个文本 div 的字体系列,以便将其设置为我的编辑器的下拉 (SELECT) 字体选择器:
//getter for fontFamily
function getFontFamily(inner) {
var fontFamilyVal = $(inner).css("font-family");
console.log('current font family is ' + fontFamilyVal)
$("select#fontFamily option").each(function() {
this.selected = (this.value == fontFamilyVal);
});
};
但是它并不总是在 Chrome 中工作。它仅适用于没有空格的字体名称,当我有一个名称有空格的字体系列时它会失败(但在 Firefox 中可以正常工作)。