Created
January 25, 2014 21:24
-
-
Save K90j1/8623830 to your computer and use it in GitHub Desktop.
どんどん増えるフォーム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
} | |
body { | |
background: #fdd; | |
font: 30px sans-serif; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form role="form"> | |
<div class="col-xs-12"> | |
<div class="form-group"> | |
<label for="exampleInputEmail1">Email address</label> | |
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email"> | |
</div> | |
</div> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function () { | |
jQuery('#exampleInputEmail1').on('focusout', '', function () { | |
reqAddingForm('department', '#departmentDiv', '#departmentArea', depTag(), jQuery(this).attr('id')); | |
}); | |
}); | |
/** | |
* フォームを増やす | |
* | |
* @param {string} strElement 追加する要素 | |
* @param {string} deleteElement 削除する要素 | |
* @param {string} targetArea 追加するDIVエリア | |
* @param {string} addHtml 追加するHTML | |
* @param {string} idNum カウント | |
* @return {void} | |
*/ | |
function reqAddingForm(strElement, deleteElement, targetArea, addHtml, idNum) { | |
// idから番号をとる | |
var countId = parseInt(idNum.replace(strElement, '')); | |
if (jQuery('#' + strElement + countId).val() == '' | |
&& jQuery('#' + strElement + (countId + 1)).size() > 0 | |
&& jQuery('#' + strElement + (countId + 1)).val() == '') { | |
// 入力後削除したのでフォームを消す | |
jQuery(deleteElement + (countId + 1)).fadeOut('fast', function () { | |
jQuery(this).remove(); | |
}); | |
return; | |
} else if (jQuery('#' + strElement + countId).val() == '') { | |
// 未入力 | |
return; | |
} else if (jQuery('#' + strElement + (countId + 1)).size() > 0) { | |
// 次のフォームがある | |
return; | |
} | |
countId++; | |
jQuery(targetArea).append(addHtml.replace(/\?/g, countId.toString())); | |
jQuery('#' + strElement + countId).on('focusout', '', function () { | |
reqAddingForm(strElement, deleteElement, targetArea, addHtml, jQuery(this).attr('id')); | |
}); | |
} | |
function mailTag() { | |
return '<div id="mailDiv?">' + | |
'<div class="col-xs-12">' + | |
'<div class="form-group">' + | |
'<label class="sr-only" for="mailAddress?">メールアドレス?</label>' + | |
'<input type="email" class="form-control" id="mailAddress?" name="mailAddress" placeholder="メールアドレス?" maxlength="256">' + | |
'</div>' + | |
'</div>' + | |
'</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment