【发布时间】:2014-04-11 12:00:34
【问题描述】:
我有一个<input /> 标签,我想用一些特定的Div 标签包装它。我正在制作要实现此功能的自定义指令。但我面临的问题是,element 的prepend() 方法添加了整个标签,即它在目标input 标签之前开始和结束。同样,element 上的append() 方法在input 标签内附加了Div,而我真正想要的是,
在 html 上:
<input id="oldinput" custom-textbox /> <!-- custom-textbox is my directive -->
在源代码中应用指令后,我想要这个:
<div id="mynewdiv> <!-- added from directive -->
<input id="oldinput" custom-textbox /> <!-- present input tag where I'd apply my directive -->
<div id="othernewdiv" /> <!-- new div to be added from directive -->
</div> <!-- end of newly added div from directive -->
但是使用append()和prepend()函数后的结果:
<div id="mynewdiv> </div> <!-- added from directive, div ends here only -->
<input id="oldinput" custom-textbox > <!-- present input tag where I'd apply my directive, doesn't end here -->
<div id="othernewdiv" /> <!-- new div to be added from directive, it's added inside input tag -->
</div> <!-- end of newly added div from directive -->
</input> <!-- Wraps my newly added div -->
完全奇怪的行为。有人可以帮我解决这个问题吗?
【问题讨论】:
标签: html angularjs angularjs-directive