日期:2014-05-17 浏览次数:20657 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> body {font-size:12px;} </style> </head> <body> <input id="text" /> <div id="div"></div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } $('text').onkeyup = function(){ $('div').innerHTML = this.value; } </script> </body> </html>
------解决方案--------------------
<input id='i'/> <div id='d' style='width:300px; height:50px; border:1px solid #ccc'></div> <script> var ipt = document.getElementById('i'); var div = document.getElementById('d'); ipt.onkeyup = function() { div.innerHTML = this.value } </script>
------解决方案--------------------
<input type="text" onkeyup="toSpan(this);" /><span id="span1"></span>
<script type="text/javascript">
function toSpan(obj) {
document.getElementById('span1').innerHTML = obj.value;
}
</script>
------解决方案--------------------
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> body {font-size:12px;} </style> </head> <body> <input id="text" /> <div id="div"></div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } $('text').onkeyup = function(){ if( this.value.length > 6 ){ $('div').innerHTML = this.value.substring(0,6) + '...'; }else{ $('div').innerHTML = this.value; } } </script> </body> </html>