<tr>
<td class="right">
<span>*</span>驗證碼:</td>
<td width="165px">
<input name="checkcode" type="text" maxlength="4" class="login_input" style="width: 80px"
id="checkcode" runat="server" /></td>
<td width="146px">
<img src="Common/getcode.aspx" id="safecode" onclick="reloadcode();" style="cursor: pointer"
height="40px" alt="看不清楚,換一張" title="看不清楚,換一張" /></td>
<td class="left">
<img id="imgRead" src="sound/maintb.gif" style="cursor: pointer;" alt="收聽驗證碼" title="收聽驗證碼"
onclick="playvoice('player');" align="absmiddle" />
</td>
</tr>
=================================================================================================
<script language="javascript" type="text/javascript" event="onkeydown" for="document">
if( event.keyCode==81 && event.altKey)
{
document.suggestForm.verifycode.focus();
playvoice("player");
}
</script>
<script type="text/javascript" language="javascript">
function reloadcode()
{
var verify=document.getElementById('safecode');
verify.setAttribute('src','../Common/getcode.aspx?'+Math.random());
}
function playvoice(id)
{
var voiceid = document.getElementById(id);
voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src='sound/sound_play.swf?" + (new Date().getTime()) + "' FlashVars='isPlay=1&url=CodeVoice.aspx&code=" + Math.random() + "' width='0' height='0' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}
</script>
備注:
1、Registe.aspx(放有讀取驗證碼功能的頁面)需要放在根目錄下。(放在文件夾下面的話語音功能不能使用,原因暫時不明確)
2、sound文件夾下面存放的文件有:begin.mp3;end.mp3 和 sound_play.swf這3個文件。
根目錄下CodeVoice.aspx(頁面代碼全部刪除,只留頭文件即可)
cs代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
//讀取驗證碼生成mp3,這裡包括頭部begin.mp3和尾部end.mp3
Response.ContentType = "audio/mpeg";
Response.WriteFile("Sound/begin.mp3");
string checkCode = "";
if (Session["CheckCode"] != null)
{
checkCode = Session["CheckCode"].ToString();
}
if (checkCode.Length > 0)
for (int i = 0; i < checkCode.Length; i++)
{
Response.WriteFile("Sound/" + checkCode[i] + ".mp3");
}
Response.WriteFile("Sound/end.mp3");
}
摘自:hongjiaoli的專欄