您希望代表inlne css更改值,就像我在div <div style = "font-family:arial"></div>
中设置的那样<select>
值将显示第一个选项,如果我在div <div style = "font-family:quicksandregular"></div>
中设置所以{{1 }}将显示选择的第三个选项
我很困惑,如何使用jQuery实现这一切所有这些都发生在运行时。我的代码如下所述,您也可以查看fiddle here
HTML
<select>
SCRIPT
<select name="select" id="editorFontN">
<option value="arial">font 1</option>
<option value="alex_brushregular">font 2</option>
<option value="quicksandregular">font 3</option>
</select>
<div style="font-family:quicksandregular"></div>
答案 0 :(得分:1)
尝试
var Default = $('div').css('font-family')
var sele = $('#editorFontN')
sele.val($('div').css('font-family'))
答案 1 :(得分:1)
sele.val($('div').css('font-family'));
答案 2 :(得分:0)
<强> DEMO 强>
试试这个
var Default = $('div').css('font-family')
var sele = $('#editorFontN');
if ($('div').css('font-family') == "arial") {
sele.prop('selectedIndex', 0);
} else if ($('div').css('font-family') == "alex_brushregular") {
sele.prop('selectedIndex', 1);
} else if ($('div').css('font-family') == "quicksandregular") {
sele.prop('selectedIndex', 2);
}
希望这有帮助,谢谢