棋盤測試頁, 另申請html權限
2008-02-21 18:34 | LCH
先貼上代碼, 先試試效果
不知可行性如何
先測試比較簡單的: 著色..
[CODE]<script type="text/javascript">
var red = '硨|碼|相|仕|帥|炮|兵';
var black = '車|馬|象|士|將|包|卒';
function paintColor(inputtext)
{
redRegExp = new RegExp("("+red+")", "gm");
result = inputtext.replace(redRegExp,"<font color='red'>$1</font>");
blackRegExp = new RegExp("("+black+")", "gm");
result = result.replace(blackRegExp,"<font color='blue'>$1</font>");
return result;
}
function getElements()
{
var x=document.getElementsByTagName("code");
for ( i = 0 ; i < x.length ; i++ )
{
x[i].innerHTML = paintColor(x[i].innerHTML);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(getElements);
</script>[/CODE]
不知可行性如何
先測試比較簡單的: 著色..
[CODE]<script type="text/javascript">
var red = '硨|碼|相|仕|帥|炮|兵';
var black = '車|馬|象|士|將|包|卒';
function paintColor(inputtext)
{
redRegExp = new RegExp("("+red+")", "gm");
result = inputtext.replace(redRegExp,"<font color='red'>$1</font>");
blackRegExp = new RegExp("("+black+")", "gm");
result = result.replace(blackRegExp,"<font color='blue'>$1</font>");
return result;
}
function getElements()
{
var x=document.getElementsByTagName("code");
for ( i = 0 ; i < x.length ; i++ )
{
x[i].innerHTML = paintColor(x[i].innerHTML);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(getElements);
</script>[/CODE]