此脚本应返回结果并显示结果"回答" >段 但相反它会暂时出现 消失了,我想念的是什么?
< script >
function dataValidation() {
var initial = document.getElementById("anyWord").value
var char = /[^а-яА-Я]/
if (initial == null || initial == "") {
alert('Please, enter only cyrillic letters.')
} else if (initial.match(char)) {
alert('Please enter only cyrillic')
} else shmovoConverter()
}
function shmovoConverter() {
var sAnyWord = document.getElementById('anyWord').value
var shm = 'Шм'
var vowels = ['а', 'у', 'о', 'ы', 'и', 'э', 'я', 'ю', 'ё', 'е', 'а', 'у']
var consonants = ['б', 'в', 'г', 'д', 'ж', 'з', 'й', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ']
for (var i = 0; i < vowels.length; i++) {
var firstLater = sAnyWord.substring(0, 1)
if (firstLater === vowels[i]) {
alert(shm + sAnyWord)
var sAnswer = shm + sAnyWord
document.getElementById('answer').innerHTML = sAnswer
} else {
for (var j = 0; j < consonants.length; j++) {
if (firstLater === consonants[j]) {
sAnyWord = sAnyWord.substring(1, sAnyWord.length)
i = 0
}
}
}
}
}
< /script>
&#13;
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Registration Form</title>
</head>
<body style="background-color: #FFFFCC">
<div style="margin-left: 200px;
margin-top: 100px;
margin-bottom: auto;
margin-right: 400px;
border: solid;
border-color: #D6BA01;
background-color: #F5DEB3">
<form id="RegForm">
<p style="margin-left: 10px" align="center">Slovo - Shmovo</p>
<p style="margin-left: 10px">Enter any word:
<input type="text" id="anyWord">
</p>
<p></p>
<p style="margin-left: 10px">
<input type="submit" name="submit" value="Submit" id="submitBtn" onclick="dataValidation()" />
</p>
<p id="answer"></p>
</form>
&#13;
此脚本应返回结果并显示结果&#34;回答&#34;段落,但它似乎暂时出现然后消失了,我想念的是什么?
答案 0 :(得分:0)
如果结果显示(在你提供的代码中没有),这里的问题是你已经提交(没有处理程序,只刷新页面),将类型改为&#34;按钮&# 34;不是&#34;提交&#34;或者用按钮元素替换
答案 1 :(得分:0)
当您按下按钮时,表单提交并加载页面的问题 你可以通过一种方式解决这个问题: -
1-制作表单标记<form id="RegForm" action="#">
2-点击你的按钮就像<input type="submit" name="submit" value="Submit" id="submitBtn" onclick="dataValidation();return false;" />
将解决您的问题