帝國CMS二次開發后的效果
1、首先把會員的“userpic”字段設置為文本類型,主要用來存頭像路徑。然后在新建一個“userpic2”字段,主要用來上傳頭像。
2、隨機頭像圖片代碼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | < table width = "100%" > < tr > < td valign = "top" >隨機圖像:</ td > < td bgcolor = 'ffffff' > < img src = '/e/template/Style/img/1.jpg' id = 'img2' width = "180" height = "180" /> </ td > </ tr > < tr > < td colspan = "2" height = "20" ></ td > </ tr > < tr > < td colspan = "2" >< a class = "changeImg" href = "javascript:void(0)" onclick = "ChangeFace()" >換一張</ a > </ td > </ tr > < tr > < td colspan = "2" height = "20" ></ td > </ tr > < tr > < td colspan = "2" align = "center" > < button class = "editPassword-submit" type = "submit" id = "faceSubmit" >使用頭像</ button > </ td ></ tr > </ table > < script type = "text/javascript" > function ChangeFace() { //x上限,y下限 var x = 10; var y = 1; var rand = parseInt(Math.random() * (x - y + 1) + y); var face = '/e/template/Style/img/' + rand + '.jpg'; $("#img2").attr('src', face); $("input[name='userpic']").attr('value', face); } </ script > |
3、userpic字段代碼
1 2 | <input name= "userpic" type= "text" id= "userpic" value= "<?=$ecmsfirstpost==1?" ":ehtmlspecialchars(stripSlashes($addr[userpic]))?>" size= ""
"display:none" > <?= empty ( $addr [userpic])? "" : "<img src='" .ehtmlspecialchars( stripSlashes ( $addr [userpic])). "' border=0 id=img2>" ?><br> |
4、userpic2字段代碼
1 2 | <input type= "file" name= "userpic2file" size= "45" > <input name= "userpic2" type= "text" id= "userpic2" value= "<?=$ecmsfirstpost==1?" ":ehtmlspecialchars(stripSlashes($addr[userpic2]))?>" size= ""
"display:none" > |
5、給表單上傳圖片提交按鈕設置一個ID
1 | < input type = 'submit' name = 'Submit' value = '上傳頭像' onclick = "bt();" > |
讓他在提交前,把上傳的userpic2字段內容賦值到userpic字段里面。
1 2 3 4 | function bt(){ var txt = $( "input[name='userpic2']" ).val(); $( "input[name='userpic']" ).attr( 'value' ,txt); } |
這樣就可以了,點擊左邊的“上傳圖片”按鈕會把userpic2的內容給userpic,點擊右邊的“使用頭像”按鈕,也會把隨機生成的頭像地址賦值給userpic。
個人覺得挺麻煩的,主要是不想改程序,就用這種“障眼法”來完成。
|
新聞熱點
疑難解答