我有一个那些时刻是我无法得到一个简单的代码工作。尽管花费了一个多小时,但我无法获得这段代码的工作。简单的jQuery模糊功能不起作用
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo 'Test'; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"><!-- jQuery stylesheet -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script><!-- jQuery libary -->
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script><!-- jQuery UI -->
</head>
<body>
<script>
$("#target").blur(function() {
alert("Handler for .blur() called.");
});
</script>
<form>
<input id="target" type="text" value="Field 1">
<input type="text" value="Field 2">
</form>
</body>
</html>
我已经通过HTML 5验证我的代码运行,以确保它是不是愚蠢的,我保证我使用的是最新版本的jQuery。奇怪的是,我可以让代码在jsFiddle上工作。
因为你的脚本运行的输入元件由之前,要么把脚本底部或使用'$(文件)。 ready'。并且它会在jsFiddle中工作,因为默认情况下,您在js框中放置的代码是运行onload –
脚本没有获取目标id,请将脚本放在主体的底部 – Newinjava