我已经编写了一个jQuery插件作为表单元素,我想在整个mysite中重用它。
(function ( $ ) {
$.fn.create = function() {
var form = '<div id="form" class="container">';
form += '<div>User Login</div>';
form += '<form action="/create" method="post">';
form += '<input type="text" name="name" placeholder="name">';
form += '<input type="email" name="email" placeholder="email">';
form += '<button type="submit">Login</button>';
form += '</form>';
form += '</div>';
return this.append(form);
};
}( jQuery ));
在HTML视图中,
<div id="#newForm"></div>
<script>
$(document).ready(function(){
$("#newForm").create();
});
</script>
但是,表单不会呈现在#newForm