我一直在努力使用textarea 的selectionStart和selectionEnd属性来使它们与contenteditable div元素一起工作.我已经在谷歌和SO上检查了很多相关文章,但无济于事.我有类似下面的东西,完全适用于textarea.但我希望这个与满足的div一起工作.
function replaceVal(node, val, step){
//...
var cursorLoc = node.selectionStart;
node.value = node.value.substring(0, node.selectionStart - step) + value +
node.value.substring(node.selectionEnd, node.value.length);
node.scrollTop = scrollTop;
node.selectionStart = cursorLoc + value.length - step;
node.selectionEnd = cursorLoc + value.length - step;
//...
}
Run Code Online (Sandbox Code Playgroud)
如何修改它以便它可以使用contenteditable div元素而不是textarea?
我可以在JavaMail中发送具有非ascii文件名的附件,但我无法下载它们.我特意为那些文件名包含非ascii字符的附件获取java.io.FileNotFoundException.
仅供参考:我使用的方法是messageBodyPart.setFileName(MimeUtility.encodeText(filename[i])) 对文本进行编码并MimeUtility.decodeText(bodyPart.getFileName())解码非ascii文件名
这有解决方法吗?
编辑 @Bill,这是我的代码的一部分,读取附件.我还在我的代码中添加了properties.setProperty("mail.mime.decodeparameters","true")和properties.setProperty("mail.mime.decodefilename","true")属性.
if (message[a].getContent() instanceof MimeMultipart) {
Multipart multipart = (Multipart) message[a].getContent();
for (int i = 0; i < multipart.getCount(); i++) {
bodyPart = multipart.getBodyPart(i);
disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT) || (disposition.equals(BodyPart.INLINE)))) {
DataHandler handler = bodyPart.getDataHandler();
String path = bodyPart.getFileName();
String[] str = path.split("/");
String fileName = str[str.length - 1];
String filePath = ReadConfigPropertiesFile.getPropertyValue("server.buildpath");
System.out.println(fileName);
File tempDir = new File(filePath + user);
if (!tempDir.exists()) {
tempDir.mkdir();
}
File …Run Code Online (Sandbox Code Playgroud)