1

jQuery を使用して括弧の間にテキストを配置する必要があります。検索などのアクションが発生すると、コンテンツが更新されます。

構造は次のとおりです。

<h2>Placeholder Text Placeholder Text Placeholder Text ()</h2>
4

1 に答える 1

2

indexOfメソッドを使用できます。

text = $("h2").text();
pos1 = text.indexOf("(");
pos2 = text.indexOf(")");
newText = text.substring(0, pos1 + 1) + myText + text.substring(pos2);

上記は、テキスト内に括弧のペアが 1 つだけあることを前提としています。

于 2010-04-19T11:10:38.130 に答える