如何允许我网站的用户编辑字体系列?
我想要在更改网站字体的页面上下拉。它应该立即发生,如果可能的话不需要点击按钮。
我该怎么做?
答案 0 :(得分:3)
改进 - 尝试这个小jQuery
<html>
<head><title>Test</title></head>
<body style="font-family: Helvetica;">
<select name="ListMenuId" id="ListMenuId">
<option value="">Change this</option>
<option value="1">This change the font family to Verdana</option>
</select>
<select name="ListMenu2" id="ListMenu2">
<option value="">Change for selected font-family</option>
<option value="Verdana">This change the font family to Verdana</option>
<option value="Arial">This change the font family to Arial</option>
<option value="Helvetica">This change the font family to Helvetica</option>
<option value="Times New Roman">This change the font family to Times New Roman</option>
</select>
</body>
<script type="text/javascript">
$(function(){
$('#ListMenuId').change(function(){
$('body').css('font-family', 'Verdana'); // Specific font-family
});
$('#ListMenu2').change(function(){
$('body').css('font-family', $(this).val()); // Gets font-family from list menu option value
});
});
</script>
</html>
答案 1 :(得分:0)
您可以使用jQuery轻松完成此任务:
$("body").css("font-family","Arial");