0

我有一个用于搜索的文本框。出于某种原因, .blur() 无法在我的计算机上运行。我创建了一个测试文件来测试它,它仍然无法正常工作:

<!doctype html>
<html>
 <head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    $('#search').blur(function() {
        alert('hello');
});
</script>
</head>
<body>
<input id="search" value="hello" type="text" />
</body>
</html>
4

2 回答 2

1

就像戴夫说的,试试这个:

$(document).ready(function() {
    $('#search').blur(function() {
        alert('hello');
    });
});
于 2012-06-08T18:19:51.243 回答
0

也许只是使用非 jquery 的做事方式?

document.getElementById("search").addEventListener('blur',function(){
    document.getElementById("search").value = "DEFAULT_VALUE";
});
于 2012-06-08T19:02:17.077 回答