为textarea增加tab键支持
日期: 2012-02-07 分类: Asp.Net 1061次阅读
$("textarea").on('keydown', function (e) { if (e.keyCode == 9) { e.preventDefault(); var indent = ' '; var start = this.selectionStart; var end = this.selectionEnd; var selected = window.getSelection().toString(); selected = indent + selected.replace(/\n/g, '\n' + indent); this.value = this.value.substring(0, start) + selected + this.value.substring(end); this.setSelectionRange(start + indent.length, start + selected.length); } })
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
标签:JavaScript
上一篇: access数据库使用总结
精华推荐