是否可以从一段html代码更改JavaScript中的字体?
我想"强迫" JS显示本地字体,但我无法更改JS(它不是我的脚本,而且它是混乱的)。
JS是由填字游戏程序生成的,只允许您在新罗马"时间之间做出选择。和" Sans serif"将文件导出到网页时。一切都以小写形式导出,我可以通过使用" text-transform:uppercase"来解决这个问题。使所有字母大写。为什么不能用字体做同样的事情? (是的;它适用于页面上的其他任何地方)。
这里是完整的代码:
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta NAME="Generator" CONTENT="Crossword Compiler (www.crossword-compiler.com)">
//this is my stylesheet to call @font-face.
<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" />
//this is from the original code. I've only added 'fatalityregular':
<STYLE TYPE="text/css"
{ "font-family: fatalityregular, Arial, Times, sans-serif";
}></STYLE>
//this whole section looks like this when you export the puzzle to web:
<!--
BODY, .Clues, .GridClues { font-size: -3pt; font-family: 'fatalityregular', Arial, Times, sans-serif;}
-->
<!--
.PuzTitle {
font-size: 15pt; color: #800000; font-weight: bold;
}
.CopyTag {
font-size: 10pt; color: #000000
}
-->
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#ffffff">
//this is what I use to fix Times/Arial. With MYFONT I won't need this (it's all uppercase):
<span style="text-transform: uppercase">
<script src="CrosswordCompilerApp/jquery.js"></script>
<script src="CrosswordCompilerApp/raphael.js"></script>
<script src="CrosswordCompilerApp/crosswordCompiler.js"></script>
<script src="MyCrossword.js"></script> //This is where I want MYFONT to be used.
<script>
$(function(){
$("#CrosswordCompilerPuz").CrosswordCompiler(CrosswordPuzzleData,null,
{SUBMITMETHOD:"POST",PROGRESS : "" , ROOTIMAGES: "CrosswordCompilerApp/CrosswordImages/" } );});
</script>
<div id="CrosswordCompilerPuz"></div>
</span>
</BODY>
</HTML>
答案 0 :(得分:0)
<span id="my-span" onclick="return change_font();" style="text-transform: uppercase;">Your Text</span>
<script>
function change_font(){
document.getElementById("my-span").style.fontFamily = "Times New Roman";
}
</script>