2

これ:

str = "test                 test"
ed.selection.setContent(str);//1

これとは異なる動作をします:

ed.selection.setContent("test                 test");//2

私はテキスト エディターで作業しており、setContent はテキスト ボックスに値を設定します。1 はテキストボックスの値を

"test test"

そして2はそれをに設定します

"test                 test".

ハードコーディングされた値ではなく、プログラムで変数のみを使用できます。私は何をすべきか?なぜこれが起こるのですか?

4

3 に答える 3

1

Are you using tinyMCE? (Please retag your question)
Their DOCs specificy:

this will cleanup the content before it gets set using the different cleanup rules options

Try adding: {format : 'raw'} after the string, like so:

ed.selection.setContent("test                 test", {format : 'raw'});

On both accounts, and see if it helps.

Edit (final, I hope):
use str = str.replace(/\s/g, ' '); before inserting it to the function.
You can test it here, this should work.

于 2012-10-10T12:21:08.830 に答える
1

いいえ、違いはありません。動作が本当に異常な場合は、グローバル変数への代入がstrコードの残りの部分を混乱させます。varキーワードを追加してローカルにします。

于 2012-10-10T12:13:22.033 に答える
0

ここでの問題は、(キーボードごとではなく) 一度に複数のスペースを挿入すると、ブラウザーがそれらを 1 つのスペースとして表示することです。

ユーザーがスペースを入力すると、ブラウザーの動作をだますために保護されたスペースとして入力されたスペースがいくつかあります。setContent メソッドを使用せずにコンテンツを挿入する場合、同じ外観にするために、1 秒ごとのスペースを保護されたスペースに置き換える必要があります。

于 2012-10-10T12:58:03.250 に答える