add_dns.js.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <script>
  2. function elementHideShow(elementToHideOrShow){
  3. var el = document.getElementById(elementToHideOrShow);
  4. el.style.display = el.style.display === 'none' ? 'block' : 'none';
  5. }
  6. $(document).ready(function(){
  7. $('.add-ns-button').click(function(){
  8. var n = $('input[name^=v_ns]').length;
  9. if(n < 8){
  10. var t = $($('input[name=v_ns1]').parents('tr')[0]).clone(true, true);
  11. t.find('input').attr({value:'', name:'v_ns'+(n+1)});
  12. t.find('span').show();
  13. $('tr.add-ns').before(t);
  14. }
  15. if( n == 7 ) {
  16. $('.add-ns').hide();
  17. }
  18. });
  19. $('.remove-ns').click(function(){
  20. $(this).parents('tr')[0].remove();
  21. $('input[name^=v_ns]').each(function(i, ns){
  22. $(ns).attr({name: 'v_ns'+(i+1)});
  23. i < 2 ? $(ns).parent().find('span').hide() : $(ns).parent().find('span').show();
  24. })
  25. $('.add-ns').show()
  26. });
  27. $('input[name^=v_ns]').each(function(i, ns){
  28. i < 2 ? $(ns).parent().find('span').hide() : $(ns).parent().find('span').show();
  29. });
  30. });
  31. </script>