我對JavaScript很陌生,但正在嘗試編寫一個將文本數字轉換爲圖像(數字)的腳本。我該怎麼辦?將數字0-9轉換爲圖像?
P.s.我確實在網上找到了這個代碼,但它似乎很希望。
<script language="JavaScript1.1" type="text/javascript">
function phils_image_price(input)
{
//declare variables
var output=""
var position=0
var chr=""
//loop
for (var position=0; position < input.length; position++)
{
chr=input.substring(position,position+1)
//replace
if (chr == '£') {output=output + '<img border="0"
src="img/pound.gif">'}
else if(chr == '0') {output=output + '<img border="0"
src="img/0.gif">'}
else if(chr == '1') {output=output + '<img border="0"
src="img/1.gif">'}
else if(chr == '2') {output=output + '<img border="0"
src="img/2.gif">'}
else if(chr == '3') {output=output + '<img border="0"
src="img/3.gif">'}
else if(chr == '4') {output=output + '<img border="0"
src="img/4.gif">'}
else if(chr == '5') {output=output + '<img border="0"
src="img/5.gif">'}
else if(chr == '6') {output=output + '<img border="0"
src="img/6.gif">'}
else if(chr == '7') {output=output + '<img border="0"
src="img/7.gif">'}
else if(chr == '8') {output=output + '<img border="0"
src="img/8.gif">'}
else if(chr == '9') {output=output + '<img border="0"
src="img/9.gif">'}
else if(chr == '.') {output=output + '<img border="0"
src="img/dot.gif">'}
else {output=output + chr}
}
return output;
}
</script>
</head>
<body>
<script language="JavaScript1.1" type="text/javascript">
document.write('£12345678.90')
document.write('<br>')
document.write(phils_image_price('£12345678.90'))
</script>
只是一個問題,你爲什麼不想做呢? – unkn0wn 2013-05-08 22:41:30
我在猜測captcha或類似的東西? – adeneo 2013-05-08 22:45:13
@adeneo很明顯,做出一個價格;我猜想user2364094想要實現類似於[this](http://riii.nl/w9349)的事情(繼續,更改url中的數字)。 – RobIII 2013-05-08 22:48:52