相关疑难解决方法(0)

contenteditable,在文本末尾设置插入符号(跨浏览器)

Chrome中的输出:

<div id="content" contenteditable="true" style="border:1px solid #000;width:500px;height:40px;">
    hey
    <div>what's up?</div>
<div>
<button id="insert_caret"></button>
Run Code Online (Sandbox Code Playgroud)

我相信FF看起来像这样:

hey
<br />
what's up?
Run Code Online (Sandbox Code Playgroud)

IE中:

hey
<p>what's up?</p>
Run Code Online (Sandbox Code Playgroud)

不幸的是,没有很好的方法来制作它,以便每个浏览器插入一个<br />而不是div或p-tag,或者至少我在网上找不到任何东西.


无论如何,我现在要做的是,当我按下按钮时,我希望将插入符号设置在文本的末尾,所以它应该看起来像这样:

hey
what's up?|
Run Code Online (Sandbox Code Playgroud)

任何方式这样做,所以它适用于所有浏览器

例:

$(document).ready(function()
{
    $('#insert_caret').click(function()
    {
        var ele = $('#content');
        var length = ele.html().length;

        ele.focus();

        //set caret -> end pos
     }
 }
Run Code Online (Sandbox Code Playgroud)

html javascript cross-browser caret contenteditable

104
推荐指数
3
解决办法
5万
查看次数

如何将光标移动到可信实体的末尾

我需要contenteditable像在Gmail备注小部件上一样将插入符移动到节点的末尾.

我在StackOverflow上读取了线程,但这些解决方案基于使用输入,它们不适用于contenteditable元素.

javascript contenteditable cursor-position

73
推荐指数
7
解决办法
5万
查看次数

使用正则表达式从文本中删除连续的重复单词并显示新文本

HY,

我有以下代码:

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.*;

/
public  class RegexSimple4
{

     public static void main(String[] args) {   

          try {
              Scanner myfis = new Scanner(new File("D:\\myfis32.txt"));
              ArrayList <String> foundaz = new ArrayList<String>();
              ArrayList <String> noduplicates = new ArrayList<String>();

              while(myfis.hasNext()) {
                  String line = myfis.nextLine();
                  String delim = " ";
                  String [] words = line.split(delim);

                  for (String s : words) {                    
                      if (!s.isEmpty() && s != null) {
                          Pattern pi = Pattern.compile("[aA-zZ]*");
                          Matcher ma = pi.matcher(s);

                          if (ma.find()) …
Run Code Online (Sandbox Code Playgroud)

java regex string substring substitution

4
推荐指数
1
解决办法
8853
查看次数