我在 DIV 中有一个无法修改的文本区域。
我需要在带有 javascript 的文本区域后面添加一个元素,一个输入复选框。
这是代码:
<div id="msgrapidosinick"><p class="msguser">My Wall</p>
<form method="post" id="messaggioajaxd" name="frm2">
<textarea class="areamsgnoava" name="messaggio"></textarea>
<input type="hidden" value="1" name="invia" id="invia">
<input type="hidden" value="1" name="riceve" id="riceve">
<input type="hidden" value="/assyrian" name="pagina" id="pagina">
<input type="submit" value="Share" class="submsg" name="senda2" style="display: none;">
</form>
</div>
因此,当单击文本区域时,我需要在文本区域之后添加一个元素,即输入复选框。
我该怎么做?
请帮助我。
只是为了让您知道我的网站也加载了 jQuery 1.3.2
谢谢
最佳答案
您可以使用恰当命名的 after()方法:
$("textarea[name=messaggio]").click(function() {
$(this).after("<input type='checkbox' name='yourCheckBoxName' />");
});
如果您想避免创建已存在的复选框,您可以执行以下操作:
$("textarea[name=messaggio]").click(function() {
var $this = $(this);
if (!$this.next(":checkbox").length) {
$this.after("<input type='checkbox' name='yourCheckBoxName' />");
}
});
关于javascript - 使用 Javascript 或 jQuery 在文本区域后 append 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6175156/