Я не знаю, как описать мою проблему, но в основном:
Я написал код проекта в JSFiddle для удовольствия, и каким-то образом мой вывод кода просто перепрыгивает вверх и вниз.
Если вы хотите посмотреть сами, нажмите на ссылку ниже, а затем нажмите кнопку «Отправить жалобу».
Проблема: В выходном тексте некоторые переменные и текст выше, чем весь окружающий текст.Я не знаю почему.
Спасибо за попытку помочь!
Мой проект на JSFiddle
Вот рабочий фрагмент:
$("#textChanger").click(function() {
var el = $("#alarmcard"),
newone = el.clone(true);
el.before(newone);
$("." + el.attr("class") + ":last").remove();
});
$("input:checkbox").on('click', function() {
// in the handler, 'this' refers to the box clicked on
var $box = $(this);
if ($box.is(":checked")) {
// the name of the box is retrieved using the .attr() method
// as it is assumed and expected to be immutable
var group = "input:checkbox[name='" + $box.attr("name") + "']";
// the checked state of the group/box on the other hand will change
// and the current value is retrieved using .prop() method
$(group).prop("checked", false);
$box.prop("checked", true);
} else {
$box.prop("checked", false);
}
});
.fieldset {
visibility:hidden;
}
.typewriter {
vertical-align: baseline;
display: flex;
color: black;
font-family: monospace;
overflow: hidden;
/* Ensures the content is not revealed until the animation */
border-right: .15em solid orange;
/* The typwriter cursor */
white-space: nowrap;
/* Keeps the content on a single line */
margin: 0 auto;
/* Gives that scrolling effect as the typing happens */
letter-spacing: .15em;
/* Adjust as needed */
animation: typing 3.5s steps(30, end), blink-caret .5s step-end infinite;
}
/* The typing effect */
@keyframes typing {
from {
width: 0
}
to {
width: 100%
}
}
/* The typewriter cursor effect */
@keyframes blink-caret {
from,
to {
border-color: transparent
}
50% {
border-color: orange
}
}
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Telephone Alarm Card</title>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<h1>Telephone Alarm Card</h1>
<form>
<fieldset>
<legend>Submission</legend>
<p>
<label>Location in House</label>
<input type="text" id="location" placeholder="Attic" />
</p>
<p>
<label>Address of House</label>
<input type="text" id="address" placeholder="11 No. Elm, City" />
</p>
<p>
<label>Name of Suspect</label>
<input type="text" id="nameofsus" placeholder="Mrs. Blake" />
</p>
<p>
<label>Name or Initials of Submiter</label>
<input type="text" id="nameofsub" placeholder="E.B." />
<br>
<br>
<label><input type="checkbox" id = "male" name="fooby[1][]" />Male</label>
<label><input type="checkbox" id = "female" name="fooby[1][]" />Female</label>
<br>
<br>
<input type="button" value="Submit Complaint" id="textChanger" />
</fieldset>
<br>
<br>
<div id="fieldset" class="fieldset">
<fieldset>
<legend>Firemen's Alarm Card</legend>
<br>
<div id="alarmcard" class="typewriter">
<p>Have reason to suspect </p>
<div id="firstDiv">
<p>attic</p>
</div>
<p>; </p>
<div id="secondDiv">
<p>11 No. Elm, City</p>
</div>
<p>. --- </p>
<div id="thirdDiv">
<p>E.B</p>
</div>
<p>; Name is </p>
<div id="fourthDiv">
<p>Elise Larsson</p>
</div>
<p>; </p>
<div id="fifthDiv">
<p>Female</p>
</div>
</div>
<script>
document.getElementById("textChanger").onclick = function() {
document.getElementById("fieldset").style.visibility = "visible";
if (document.getElementById("location").value != "") {
document.getElementById("firstDiv").innerHTML = document.getElementById("location").value;
} else {
document.getElementById("firstDiv").innerHTML = "attic";
}
if (document.getElementById("address").value != "") {
document.getElementById("secondDiv").innerHTML = document.getElementById("address").value;
} else {
document.getElementById("secondDiv").innerHTML = "11 No. Elm, City";
}
if (document.getElementById("nameofsub").value != "") {
document.getElementById("thirdDiv").innerHTML = document.getElementById("nameofsub").value;
} else {
document.getElementById("thirdDiv").innerHTML = "Mrs. Blake";
}
if (document.getElementById("nameofsus").value != "") {
document.getElementById("fourthDiv").innerHTML = document.getElementById("nameofsus").value;
} else {
document.getElementById("fourthDiv").innerHTML = "E.B.";
}
if (document.getElementById("male").checked == true) {
document.getElementById("fifthDiv").innerHTML = "Male";
} else if (document.getElementById("female").checked == true) {
document.getElementById("fifthDiv").innerHTML = "Female";
}
}
</script>
<br>
</fieldset>
</div>
</form>
</body>
</html>