我试图让框出现在按钮顶部,但是在现有div框的底部。
<div id="top_form">
<form>
Street: <input name="titles[]" type="text" placeholder="eg: 123 Fake st."><br><br>
City: <input name="titles[]" type="text" placeholder="eg: Bellflower">
<select>
<option value=" ">State</option>
<option value="ca">CA</option>
<option value="az">AZ</option>
<option value="de">DE</option>
</select>
Zip: <input name="titles[]" type="text" placeholder="eg: 91745"><br />
</form>
</div>
<br />
<a id="awsomeButton" href="#">+ Add Loction</a>
继承剧本
var tpl = ""
+ "<div id='location_div_<%= id %>'><h1>My Location #<%= id %></h1></div>";
var newId = new Date().getTime();
var template = _.template(tpl);
var compiled = template({id: newId});
var form = ""
+ "<div id='added_form'><a href='#' class='close_btn'>x</a><form> Street: <input name='titles' type='text'><br /><br />City: <input name='titles' type='text'><select><option value=' '>State</option><option value='ca'>CA</option></select>Zip: <input name='titles' type='text'></form></div>"
$('#awsomeButton').on('click',
function(e){
$(form).hide().appendTo('body').fadeIn('slow');
});
答案 0 :(得分:2)
而不是
.appendTo('body')
将添加到
.appendTo('#top_form')
最好将你的top_form包含在另一个div中
<div id="container" >
<div id="top_form">
并将其附加到容器中......
.appendTo('#container')
<强> Check Fiddle 强>