Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Created April 10, 2017 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/dbd1cdc528b586a39001192c49aeddd2 to your computer and use it in GitHub Desktop.
Save MOOOWOOO/dbd1cdc528b586a39001192c49aeddd2 to your computer and use it in GitHub Desktop.
js form
<form id="id-form" hidden="hidden">
<input id="id-input" type="text" title="input">
<input id="id-input-submit" type="submit" value="submit">
</form>
<button id="id-button-toggle" data-hide="show-form" data-show="hide-form">show</button>
<script src="toggle-button-key.js"></script>
var form = {}
form.formQuery = function (selector) {
var tags = selector.find('[title]')
var f = {}
for (var tag of tags) {
var key = tag.title
f[key] = tag.value
}
return f
}
form.toggle = function (form_jquery, button_jquery) {
var text_show = button_jquery.data('show')
var text_hide = button_jquery.data('hide')
button_jquery.text(text_show)
button_jquery.on('click', function () {
var display = form_jquery.css('display')
if (display != 'none') {
form_jquery.slideUp()
$(this).text(text_show)
} else {
form_jquery.slideDown()
$(this).text(text_hide)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment