0

currently, I'm trying to have the user select a font from the drop-down box and when the pick lets say Times New Roman, all the text on the page changes to that font. 我已经掌握了基础知识,但我无法弄清楚放置的顺序。

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script>
  //text
   $("#font option:selected").val();

  </script>
</head>

<body>
<div id="about_turtles">
  <center><p>This is a test</p></center>
</div>

<div id="font_buttons">
  <select id="font">
  <option value="helvetica">Helvetica</option>
  </select>
</div> 
4

2 回答 2

3

你可以使用这个简单的代码:

 $(document).ready(function(){

$('#font').change(function(){
var font = $(this).val();

$('*').css("font-family", font);
});


});
于 2018-10-07T20:02:44.087 回答
0

从它的外观来看,您只能获得所选内容的价值。

但是我认为你所追求的是一个事件监听器。像这样的东西:

$("#font").change(function () {
    var family= this.value;
    $("#about_turtles").css("font-family",family);
  });

我还将字体系列名称存储在您选择列表中每个选项元素的值中。

工作 JSFiddle

看看这个以获得更多帮助:jQuery改变字体系列和字体大小

于 2018-10-07T19:51:02.240 回答