我似乎无法验证百分比。 需要你帮我解决一下!
function validate()
{
s
if( document.myForm.outputPercentage.value <= 0||>=100
{
alert( "Please the correct percentage." );
document.myForm.outputPercentage.focus() ;
return false;
<form name="myForm" onsubmit="return(validate());">
Last output percentage: <input type"text" name="outputPercentage" id="outputPercentage" />&<br/><br/>
<input type="submit" value="Submit" />
答案 0 :(得分:0)
我已修正您的代码,以便它可以正常运行:
<html>
<head>
<script type="text/javascript">
function validate() {
var outputPercentageString = document.myForm.outputPercentage.value;
var outputPercentage = parseInt(outputPercentageString);
if (outputPercentage <= 0 || outputPercentage >= 100) {
alert("Please the correct percentage.");
document.myForm.outputPercentage.focus();
return false;
}
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return(validate());">
Last output percentage: <input type="text" name="outputPercentage" id="outputPercentage" />%
<br/><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
type"text"
应为type="text"
{
,则必须在之后关闭}
<script>
元素中的<head>
标记<html>
个元素中。希望这有帮助。