扫码关注官方订阅号
鼠标移动到如图右边的文字上,文本出现编辑状态。
当鼠标移出,又恢复到文字状态。
我只知道 onmouseout 和 onmouseover ,可能是太菜了,感觉不好实现,请各位知道的大侠恳请指点下,给出实现的大概方法或者需要用到的函数等等....
拜谢了‵‵
小伙看你根骨奇佳,潜力无限,来学PHP伐。
<style> .hide { display:none; } #tx { cursor:pointer; } </style> <p id="tx">blablabla</p> <textarea id="ta" class="hide"></textarea> <script> var tx = document.getElementById('tx'), ta = document.getElementById('ta'), toggleEL = function(el, fn){ var cls = el.className, _cls = (cls == '') ? 'hide': ' hide'; if (cls.indexOf('hide')===-1) { el.className += _cls; }else { el.className = cls.replace('hide', ''); } if (fn) fn(); }; tx.onmouseover = function(){ toggleEL(tx, function(){ toggleEL(ta); ta.focus(); }); } </script>
//修改 tx.onmouseover tx.onmouseover = function(){ toggleEL(tx, function(){ toggleEL(ta); ta.value = tx.innerText; ta.focus(); }); } //js中增加 ta.onmouseout = function(){ toggleEL(ta, function(){ toggleEL(tx); }); }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
<style> .hide { display:none; } #tx { cursor:pointer; } </style> <p id="tx">blablabla</p> <textarea id="ta" class="hide"></textarea> <script> var tx = document.getElementById('tx'), ta = document.getElementById('ta'), toggleEL = function(el, fn){ var cls = el.className, _cls = (cls == '') ? 'hide': ' hide'; if (cls.indexOf('hide')===-1) { el.className += _cls; }else { el.className = cls.replace('hide', ''); } if (fn) fn(); }; tx.onmouseover = function(){ toggleEL(tx, function(){ toggleEL(ta); ta.focus(); }); } </script>//修改 tx.onmouseover tx.onmouseover = function(){ toggleEL(tx, function(){ toggleEL(ta); ta.value = tx.innerText; ta.focus(); }); } //js中增加 ta.onmouseout = function(){ toggleEL(ta, function(){ toggleEL(tx); }); }