<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>注音文字測試</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#t").change(function () {
//取得文字長度, select數要相等
var len = $(this).val().length;
//移除多餘的select
var $altBlock = $("#spnAlt");
$altBlock.find("select:gt(" + (len-1) + ")").remove();
//取現有select數
var curLen = $altBlock.find("select").length;
//補足字元數個select
for (var i = curLen; i < len; i++)
$altBlock.append(
"<select><option value='0'>0</option>" +
"<option value='1'>1</option>" +
"<option value='2'>2</option>" +
"<option value='3'>3</option></select>");
}).change();
$("#bc,#fc").change(function () {
$(this).parent().find(".c").css("background-color", "#" + this.value);
}).change();
//任何欄位變動後就重新顯示
$("input,select").live("change", function () {
//組成URL
var url = "ChWordImage.ashx?t=" + escape($("#t").val()) +
"&w=" + $("#w").val() + "&h=" + $("#h").val() +
"&bc=" + $("#bc").val() + "&fc=" + $("#fc").val() +
"&af=" + getAltFont() + "&fs=" + $("#fs").val();
//設定圖檔產生參數
$("#preview").attr("src", url);
//取得破音字型切換
function getAltFont() {
var v = [];
$("#spnAlt").find("option:selected").each(function () {
v.push(this.value);
});
return v.join('');
}
});
//觸發初始change
$("input:first").change();
});
</script>
<style type="text/css">
body { font-size: 11pt; background-color: #444444; color: yellow; }
#bc,#fc { width: 50px; }
#w,#h,#fs { width: 50px; }
input.c { border: 1px dotted black; width: 40px; }
span { margin: 3px; }
div { padding: 4px; }
</style>
</head>
<body>
<div>
<div><span>寬 度:</span><input type="text" id="w" value="256"/></div>
<div><span>高 度:</span><input type="text" id="h" value="50"/></div>
<div><span>文 字:</span><input type="text" id="t" value="黑暗執行緒" /></div>
<div><span>破音字:</span><span id="spnAlt"></span></div>
<div><span>大 小:</span><input type="text" id="fs" value="20" /></div>
<div><span>顏 色:</span><input type="text" id="fc" value="ffffff" />
<input class='c' readonly /></div>
<div><span>底 色:</span><input type="text" id="bc" value="af2f00" />
<input class='c' readonly /></div>
<div style="padding: 5px;"><img id="preview" /></div>
</div>
</body>
</html>