[英]Page go back in history when button clicked
我有5个单选按钮的垂直无序列表,每2分钟生成一次动态文本。
<ul id="answers_ul">
<li><input class="alternative-letter" id="r1" name="r1" type="radio"><div class="answers_letters">A</div><label class="res1" for="r1"></label><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"></svg></li>
<li><input class="alternative-letter" id="r2" name="r1" type="radio"><div class="answers_letters">B</div><label class="res2" for="r2"></label><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"></svg></li>
<li><input class="alternative-letter" id="r3" name="r1" type="radio"><div class="answers_letters">C</div><label class="res3" for="r3"></label><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"></svg></li>
<li><input class="alternative-letter" id="r4" name="r1" type="radio"><div class="answers_letters">D</div><label class="res4" for="r5"></label><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"></svg></li>
<li><input class="alternative-letter" id="r5" name="r1" type="radio"><div class="answers_letters">E</div><label class="res5" for="r5"></label><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"></svg></li>
</ul>
问题如下。 我在
<button class="clean_question"></button>
命名该类后,按钮的功能是清除单选按钮的答案(如果选中)。 但是,当我单击它时,该页面将载入历史记录中的上一页! 真是疯了。
我将粘贴与clean_question按钮相关的JS和CSS
的CSS
button.clean_question{
background-color: #292f33;
border: 1px solid #55acee;
width: 60px;
height: auto;
margin-top: 5px;
border-radius: 50%;
margin-left: -34px;
float: left;
padding: 10px 12px;
z-index: 100;
position: absolute;
transition: 0.3s;
-webkit-transition: 0.3s;
}
button.clean_question:hover{
transform: scale(1.1,1.1);
}
button.clean_question:before{
content: url(../images/Examen_Botones_Clean.svg);
}
和JS
function resetRadio(el) {
[].slice.call($('input[type="radio"][name="' + el.getAttribute('name') + '"]')).forEach(function(el) {
var path = el.parentNode.querySelector('svg > path');
if (path) {
path.parentNode.removeChild(path);
}
});
}
jQuery('button.clean_question').on('click', function(){
console.log('llegaste');
selectsArr.forEach(function(obj,i) {
[].forEach.call(obj.inputs,function(el){
if (el.getAttribute('type') === 'radio')
resetRadio(el);
})
});
请尝试帮助我,我真的被这个问题困扰了。
<button type="">
属性默认为submit
。
https://www.w3.org/TR/html/forms.html#attr-button-type
因此,默认情况下单击它将提交表单。 默认情况下,表单目标是同一页面,从而导致重新加载。 使用<button type="button">
可以避免这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.