<head>
<script type="text/javascript">
function InsertChar () {
try {
var pressEvent = document.createEvent ("KeyboardEvent");
pressEvent.initKeyEvent ("keypress", true, true, window,
false, false, false, false,
0, "x".charCodeAt (0));
var input = document.getElementById ("myInput");
input.dispatchEvent (pressEvent);
}
catch (e) {
alert ("Your browser does not support this example!");
}
}
</script>
</head>
<body>
<input type="text" id="myInput" value="Input field" size="20"/>
<button οnclick="InsertChar ()">Simulate pressing the 'x' key on the input.</button>
</body>
http://write.blog.csdn.net/postedit