对添加另一个选项卡的onsubmit函数停止重定向
Stop redirect on an onsubmit function that adds another tab
我正在构建一个on-submit函数来创建一个div、id和类,用于构建一个新的选项卡。我可以看到,在提交时,它似乎确实创建了列表项,重定向会导致列表项被删除并发送回原始页面。我想在选项卡中添加内容,但一旦重定向发生,这就没用了。如果有人能指出问题发生的地方,那将是有帮助的。
/**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('');
});
});
.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;
}
<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>
您需要调用e.preventDefault()
,但忘记调用第二个。
相关文章:
- 停止对document.ready函数的重定向/刷新
- 将重定向URL链接添加到JS函数
- 阻止Javascript函数中的重定向循环
- 将网页上的链接重定向到javascript函数
- 对添加另一个选项卡的onsubmit函数停止重定向
- 可用于重定向到任何 URL 的 JavaScript 函数
- PHP: header() 函数不重定向.使用 HTML 或 JavaScript 重定向时,会话信息会丢失
- 如何使用 get() 和 res.sendFile() 函数重定向页面
- 使用 AJAX 函数在 Codeigniter 中重定向
- 链接在javascript onclick函数能够完成之前重定向页面
- 修改 PHP 函数以在操作后重定向
- 在重定向到另一个页面之前调用 JavaScript 函数 在 Javascript 的后面调用
- 是否可以将HTML重定向到javascript函数
- 当响应 JSON 对象数据计数为零时,AJAX 成功回调函数重定向到错误回调
- 将Javascript(Jquery)函数重定向到主页
- 使用javascript将用户输入的值传递到另一个html页面,并使用javascript函数重定向
- 如何在浏览器关闭事件中从javascript函数重定向到另一个aspx页面
- Javascript .onclick函数重定向到其他页面
- 函数重定向,如果Div Id在我的页面上不工作
- 当服务器会话过期时,使用javascript的settimeout()函数重定向到登录页面