まだデータがありません。
同じ内容の入力フォームを追加・削除「Repeater」
当ページのリンクには広告が含まれています。
スポンサーリンク
同じ内容の入力フォームを追加・削除できるようにするプラグイン「Looking For」を紹介します。
jQueryプラグイン「Repeater」
このプラグインを使えば、同じ内容の入力フォーム(例えば「名前」など)をページを更新せずに追加・削除することができます。
さまざまな input要素(「text」「checkbox」「option」……など)をグループにまとめて、追加・削除することができるので、使い勝手がいいですね。
スポンサーリンク
それではデモページのフォームをご覧ください。
デモのソース(HTML + jQuery)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Repeater のデモでーす。">
<title>Looking For - jQueryプラグイン</title>
</head>
<body>
<h1>Repeater のデモ。</h1>
<form action="demo.html" class="repeater">
<div data-repeater-list="group-a">
<div data-repeater-item>
<input type="text" name="sei" value="名字"/>
<input type="text" name="mei" value="名前"/>
<select name="select-input">
<option value="男性" selected>男性</option>
<option value="女性">女性</option>
</select>
<input data-repeater-delete type="button" value="削除"/>
</div>
</div>
<input data-repeater-create type="button" value="入力フォームを追加"/>
</form>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jquery.repeater.js"></script>
<script>
$(document).ready(function () {
'use strict';
$('.repeater').repeater({
defaultValues: {
'sei': '名字',
'mei': '名前',
'select-input': '女性'
},
show: function () {
$(this).slideDown();
},
hide: function (deleteElement) {
if(confirm('削除してもいーですかー?')) {
$(this).slideUp(deleteElement);
}
}
});
});
</script>
</body>
</html>
スポンサーリンク