为什么我的代码结果里面会有一个NaN? JS
<!DOCTYPEhtml><html><head><title></title><scripttype="text/javascript">functionbinary...
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function binaryToDecimal(){
var a = document.getElementById("ea").value;
var b = document.getElementById("eb").value;
// var decimal1 = document.getElementById("result1");
//result1.innerHTML = parseInt(binary1, 2);
if (a<26 && isNaN(a) == false && a%2 != 0 && a != 13 ) {
input = document.getElementById("Euserinput").value;
input = input.toLowerCase();
//inputlength = input.length;
//alert(inputlength)
for (var i = 0; i <= input.length; i++) {
order_i = input.charCodeAt(i) - 97;
//alert(order_i);
ENumber = (a*order_i+b)%26;
EChar = String.fromCharCode(ENumber + 97);
alert(EChar);
}
//result1.innerHTML = a+b;
} else {
alert("input invalid!")
}
}
</script>
</head>
<body>
<form>
<p>Affine </p>
input plain text:<br>
<textarea cols="50" rows="5" type="text" id="Euserinput" ></textarea>
<br>
input a:
<input type="text" id="ea">
<br>
input b:
<input type="text" id="eb">
<br>
<input type="button" onClick="binaryToDecimal()" Value="EEEEEEEEEEEEE" />
<p>The Result is : <br>
<span id = "result1"></span>
</p>
</form>
</body>
</html> 展开
<html>
<head>
<title></title>
<script type="text/javascript">
function binaryToDecimal(){
var a = document.getElementById("ea").value;
var b = document.getElementById("eb").value;
// var decimal1 = document.getElementById("result1");
//result1.innerHTML = parseInt(binary1, 2);
if (a<26 && isNaN(a) == false && a%2 != 0 && a != 13 ) {
input = document.getElementById("Euserinput").value;
input = input.toLowerCase();
//inputlength = input.length;
//alert(inputlength)
for (var i = 0; i <= input.length; i++) {
order_i = input.charCodeAt(i) - 97;
//alert(order_i);
ENumber = (a*order_i+b)%26;
EChar = String.fromCharCode(ENumber + 97);
alert(EChar);
}
//result1.innerHTML = a+b;
} else {
alert("input invalid!")
}
}
</script>
</head>
<body>
<form>
<p>Affine </p>
input plain text:<br>
<textarea cols="50" rows="5" type="text" id="Euserinput" ></textarea>
<br>
input a:
<input type="text" id="ea">
<br>
input b:
<input type="text" id="eb">
<br>
<input type="button" onClick="binaryToDecimal()" Value="EEEEEEEEEEEEE" />
<p>The Result is : <br>
<span id = "result1"></span>
</p>
</form>
</body>
</html> 展开
2个回答
2018-07-27
展开全部
循环里这样:for (var i = 0; i < input.length; i++)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |