在添加另一个选项卡的onsubmit函数上停止重定向

时间:2016-05-01 21:21:05

标签: javascript jquery html ajax redirect

我正在构建一个on submit函数来创建一个div,id和class,它构建一个新的选项卡。我能够在提交时看到它似乎创建了列表项,重定向导致列表项被删除并发送回原始页面。我想在选项卡中添加内容,但一旦重定向发生,这就变得毫无用处。如果有人能够证明问题发生在哪里会有所帮助。



/**Covers tab animations
May not matter just had to make sure*/
jQuery(document).ready(function(){
	jQuery('.tabs .tab-links a').on('click', function(e){
		var currentAttrValue = jQuery(this).attr('href');
		
		$('.tabs ' + currentAttrValue).show();
			$('.tabs ' + currentAttrValue).animate({opacity:1, paddingLeft:'30%'}, 400);
			$('.tabs ' + currentAttrValue).siblings().css({opacity:0, paddingLeft:'0%'});
			$('.tabs ' + currentAttrValue).fadeIn(400).siblings().hide();
		
		jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
		
		e.preventDefault();
	});
});
/** for the onsubmit functions*/
$(function(){
  //catches the information entered into form
	var $textInput = $('.examine input:text');
	
	$('#examine').on('submit', function(e){
		e.preventDefault;
		
		//puts the information into a variable
		var newText = $textInput.val();
      //adds a new tab to list
		$('li:last').append('<li><a href="#tab5">' + "newText" + '</a></li>');
      
		
		$textInput.val('');
		
		
		
	});
});
&#13;
.tab-links{
	float:left;
}
.tab-links:after {
	display:block;
	clear:both;
	content:'';
}
.tab-links li {
	list-style-type: none;
	border-bottom: 3px solid;
	letter-spacing: 0.09em;
	margin-left: -25%;
	
}
.tab-links li a {
	color: #f2f2f2;
	display: block;
	padding: 3px 10px 3px 10px;
	text-decoration: none;
}
 
.tab-links a:hover {
	background:#a7cce5;
	text-decoration:none;
}

.tab-links li.active, .tab-links li.hover {
	background-color: #e5e5e5;
	border-bottom: 3px solid #e5e5e5;
}

.tab-links li.active a, .tab-links li a:hover {
	color: #666;
	background-color: #e5e5e5;
}
 
    /*----- Content of Tabs -----*/
.tab-content {
	background-color: #e5e5e5;
	color: #666;
	min-height: 150px;
	overflow: auto;
	
}
#tab1{
	padding-left: 30%;
}
#tab2, #tab3, #tab4 {
	display:none;
	opacity: 0;
	padding-left: 0%;
}

.tab-content p {
	margin: 20px;
	text-indent: -40%;
}

 
.tab-content.active{
	display: block;
	text-indent: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="sidebar">
  <div id="explore">
    <form id="examine">
      <p>Search</p>
      <input type="search" name="explore" placeholder="Search Items" />
      <p>Choose Your Search Restrictions</p>
      <input type="radio" name="location" required= "required" value="Your School" />Inside
      <input type="radio" name="location" required= "required" value="Whole system" />Outside
      <input type="submit" value="Search" />
    </form>
  </div>
  <div class="tabs">
    <ul class="tab-links">
      <li class="active"><a href="#tab1">Tab1</a></li>
      <li><a href="#tab2">Tab2</a></li>
      <li><a href="#tab3">Tab3</a></li>
      <li><a href="#tab4">Tab4</a></li>
    </ul>

    <div class="tab-content">
      <div id="tab1" class="tab active">
        <p>Tab1 content</p>
      </div>

      <div id="tab2" class="tab">
        <p>Tab2 content</p>
      </div>

      <div id="tab3" class="tab">
        <p>Tab3 content</p>

      </div>

      <div id="tab4" class="tab">
        <p>Tab4 content</p>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您需要拨打e.preventDefault(),忘记拨打第二个。