I am trying to determine whether the value in a text box is prime or not using jQuery.
Here is what I've tried so far, but it's not working:
$("#textbx").keyup(function(){
if ($("#textbx").val().length > 0) {
$("#btn").removeAttr('disabled');
}
});
$("#textbx").blur(function(){
if ($("#textbx").val().length ==0) {
$("#btn").attr('disabled','disabled');
}
});
$("#textbx").keypress(function (e) {
if (e.which!=8 && (e.which < 48 || e.which > 57)) {
$("#msg").html("plz press nimber only").show().fadeOut("slow");
return false;
}
});
$("#btn").click(function(){
var num =parseInt($("#textbx").val());
var i;
for (var i = 2; i >num/2; i++) {
if(i%num==0)
{ $("#msg").html("yupp").show().fadeOut("slow");
}
else
{$("#msg").html("huh").show().fadeOut("slow");
}
break;
}
});
#msg
{
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<input id="textbx" type="text" /><button id="btn" disabled="disabled">go</button>
<span id="msg"></span>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…