HTML:
<textarea></textarea><br />
<a href="#">Generate</a>
<span id="output"></span>
jQuery:
$('textarea').bind('keypress', function(event) {
var charCode = event.which;
var keyChar = String.fromCharCode(charCode);
return /[a-zA-Z ]/.test(keyChar);
});
var replacements = {
'a': '1',
'b': '2',
'c': '3'
}
$('a').click(function() {
$('textarea').val(function(i, val) {
val = val.split('');
$.each(val, function(i, e) {
val[i] = replacements[e] ? replacements[e] : e;
});
return val.join('');
});
return false;
});
如何修改此现有代码以显示替换$('span#output');
?作为一个附带问题,可以进行哪些修改以使此代码更高效?