完成输入后如何显示警告框

时间:2012-03-07 23:44:38

标签: javascript input alert

我有一个这样的表格:

<form id="form1" method="post" action="">
<input maxlength="75" size="90" type="text" id="textfield2"/>
</form>

如何在完成输入后显示警告框消息? 感谢


修改

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
$(document).ready(function() {
var course_data;      
 $.get('math.xml', function(data) { 
    course_data = data;   
    var that = $('#courses');
    $('course', course_data).each(function() { 
        $('<option>').text($(this).attr('title')).appendTo(that);
    });
}, 'xml'); 
$('#courses').change(function() { 
    var val = $(this).val(); 
    var that = $('#times').empty(); 
    $('course', course_data).filter(function() { 
        return val == $(this).attr('title'); 
    })
    .find("lesson").each(function() { 
        $("#lesson").val($(this).text()); 

    });
});
});
</script>
<script type="text/javascript">
function keyPressed(event, input) {
if (event.keyCode == 8) {

    return true;
}

var char = event.which ? event.which : event.keyCode;

char = String.fromCharCode(char);
 var exerc = ["aaaa aaaa aaaa aaaa","bbbb bbbb bbbb bbbb"];
 for (i=0;i<exerc.length;i++){

 var option=document.getElementById("courses").selectedIndex;
 }

return (exerc[option - 1].charAt(input.value.length) == char);
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="text" maxlength="70" size="90" id="lesson"/>
</form>
<form name="form2" method="post" action="">
<input maxlength="59" size="90" type="text" onkeypress="return keyPressed(event, this);"/>
</form>

<form name="form1">drop1
<select style="width:100px" id='courses'>
<option selected="selected">choose...</option>
</select>
</form> 
</body>
</html>

的xml:

<courses>
<course title="chap 1">
<lesson>aaaa aaaa aaaa aaaa</lesson>
</course>
<course title="chap 2">
<lesson>bbbb bbbb bbbb bbbb</lesson>
</course>
</courses>   

我有两个输入字段,我使用按键功能只输入第二个输入中的特定字符。我可以进入,直到第一个字段的字符结束。所以,当我完成输入时,我想出现一条警告信息,如:

alert(ok finish!); 
有可能吗?

1 个答案:

答案 0 :(得分:2)

使用JQuery,你可以这样做:

$('#textfield2').bind('blur',function() {
   alert('I guess i finished typing cause I left the field!?');
});