使用JavaScript怎么實現一個驗證碼干擾功能?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ padding: 0; margin: 0; } canvas{ background: #272822; } </style> </head> <body> <canvas id='canvas' width='800' height='500'></canvas> <script> //獲得畫板 var canvas=document.getElementById('canvas'); //獲得繪畫環境 var cv=canvas.getContext('2d'); cv.fillStyle='#272822'; cv.fillRect(0,0,800,500); cv.font='80px 微軟雅黑'; cv.fillStyle='greenyellow'; cv.fillText( Math.floor(Math.random()*10000),200,200); //獲得所有的圖像像素點信息 var alldata=cv.getImageData(0,0,800,500); //獲得像素點的個數 var dian=alldata.data.length/4; for(var i=0;i<10000;i++){ //取隨機數 var num=Math.floor(Math.random()*dian); //計算像素點對應的四條信息從幾號開始 var start=(num-1)*4; alldata.data[start]=Math.floor(Math.random()*256); alldata.data[start+1]=Math.floor(Math.random()*256); alldata.data[start+2]=Math.floor(Math.random()*256); } //將數據寫回畫板 cv.putImageData(alldata,0,0); </script> </body> </html>
關于使用JavaScript怎么實現一個驗證碼干擾功能問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創新互聯行業資訊頻道了解更多相關知識。
當前名稱:使用JavaScript怎么實現一個驗證碼干擾功能-創新互聯
文章網址:http://vcdvsql.cn/article14/pgpge.html
成都網站建設公司_創新互聯,為您提供域名注冊、網站建設、網站設計、網站制作、企業建站、外貿網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯