7

I am looking for the most elegant solution for putting both rtl and ltr languages together in a textarea: e.g. arabic and html together.

The standards say not to create it using css:

direction: rtl;
unicode-bidi: embed;

This does not work for me anyway, as the html has the nested text problem. Arabic is aligned to the right but the html is broken.

Is there a way to dynamically do this? The standard wants to add a nested span tag but since a user is dynamically typing this in I don't see how that's possible without detecting the end of each character.

4

1 に答える 1

9

a のコンテンツはtextareaプレーンテキストとして扱われるためspan、そこではマークアップやその他のマークアップを使用することはできません。要素)。

ただし、プレーン テキスト レベルでは、制御文字を使用して双方向の埋め込みを強制できます。要素全体に設定すると (ユーザーが右から左への言語でデータを入力することを想定direction: rtl)、ユーザーは U+202A LEFT-TO-RIGHT EMBEDDING と入力して、英語や HTML などの左から右へのテキストを入力できます。 U+202C POP DIRECTIONAL FORMATTING と入力して、右から左へのモードに戻ります。

ほとんどの人はこれらの文字を便利に入力する方法を知らないため、ページ上にそれらのボタンを配置することができます。

<textarea id=msg name=msg rows=10 cols=40>
</textarea>
<br>
<button type=button onclick="append('\u202A')">→&lt;/button>
<button type=button onclick="append('\u202C')">←&lt;/button>
<script>
var msg = document.getElementById('msg');
function append(ch) {
  msg.innerHTML += ch;
  msg.focus();
}
</script>
于 2012-12-27T08:27:12.293 に答える