How to modify the avatar in php: first click on the avatar picture; then in the pop-up selection window, select one of them and the window will launch the avatar change. The code is [].
php method to modify the avatar:
First click on the avatar picture, a selection window will pop up, select one of them and the window Introducing avatar replacement.
Effect:
Main page code:
<tr> <td>头像:</td> <td><input type="hidden" name="face" value=""/> <img src="./face/m01.gif" alt="头像" class="face" id='faceimg' onclick="javascript:window.open('face.php','face','width=420,height=600,top=0,left=0,scrollbars=1');"/></td> </tr>
Sub-page code (pop-up form page):
<!-- 使用遍历文件夹函数,获取头像 --> <?php $facearray = _myreaddir(dirname(__FILE__)."/face"); ?>
<div id="face"> <h3>请选择头像:</h3> <?php foreach ($facearray as $num){ echo "<img src='face/".$num."' alt='face/".$num."' title='".$num."'/>"; }?> </div>
JS code used:
Quote:
<!-- 点击更换头像 --> <script type="text/javascript" src="./js/face.js"></script>
Code:
window.onload = function() { //获取face.php页面中的头像对象 var img = document.getElementsByTagName('img'); //进行循环 for(i=0;i<img.length;i++){ //对选择的对象触发点击事件 img[i].onclick = function (){ //调用 _opener()函数 _opener(this.alt); }; } } //显示头像函数 function _opener(src){ //获取父页面头像对象 var faceimg = opener.document.getElementById('faceimg'); //将头像的img更换 faceimg.src = src; //将父页面中的register表单中的name为face的值更改为src。 opener.document.register.face.value = src; }
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of How to modify avatar in php?. For more information, please follow other related articles on the PHP Chinese website!