これは私が作成しようとしている HTML です。
<td>
Tiana is
<select name="U4">...</select>
keen to go to the
<select name="J4">...</select>
market.
</td>
ご覧のとおり<td>
、途中に選択ボックスがある散文を含む要素があります。
で簡単にできます$('#id').html(...);
。私がやりたいのは、を使用してビルドすることcreateElement
です。他のテキストの真ん中に選択ボックスを作成するにはどうすればよいですか? 次のコードはスタートです:)
var doc = document,
fr = doc.createDocumentFragment(),
td = doc.createElement("td"),
sel1 = doc.createElement("select"),
sel2 = doc.createElement("select");
td.innerHTML = "Tiana is keen to go to the market";
sel1.name = "U4";
sel2.name = "J4";
fr.appendChild(td);
td.appendChild(sel1); // But these are not in the middle of the sentence
td.appendChild(sel2);
ところで: 私も、select
オプションを作成する必要があることを認識しています。
ありがとう。