我有一段 jquery 代码,当我将它加载到我的页面中时它可以工作,但是当我将它放入外部 js 文件时它不起作用。
我的外部 js 文件如下所示:
$(document).ready(function()
{
$('.list').click(function(e)
{
var value = $(this).val();
$(".select_menu input").val(value);
$(".select_menu").show();
$(".select_menu input").focus();
e.stopImmediatePropagation();
});
$('.select_menu, .select_menu input').click(function(e)
{
e.stopImmediatePropagation();
return false;
});
$(".select_menu input").bind('keyup', function(e)
{
//var e = $(event.target);
var q = $(this).val();
var dataName = $(this).attr('data-name');
$("#type").val(dataName);
selectMenu(q,dataName,e);
e.stopImmediatePropagation();
});
$(".select_menu input").focus(function(e)
{
//var e = $(event.target);
var q = $(this).val();
var dataName = $(this).attr('data-name');
$("#type").val(dataName);
selectMenu(q,dataName,e);
e.stopImmediatePropagation();
});
$(document).click(function() {
$(".select_menu").hide();
});
});
<head>
<title>Mywebsite</title>
<!-- stylesheets -->
<link type="text/css" href="../css/ui-lightness/jquery-ui-1.8.15.custom.css" rel="stylesheet" />
<link type="text/css" href="../css/green.css" rel="stylesheet" />
<link type="text/css" href="../css/nav.css" rel="stylesheet" />
<link type="text/css" href="../css/selectMenu.css" rel="stylesheet" />
<!-- jQuery - the core -->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.15.custom.min.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<script type="text/javascript" src="../js/selectMenu.js"></script>
<!-- Fancybox -->
<script type="text/javascript" src="../js/fancybox.js"></script>
<link rel="stylesheet" type="text/css" href="../css/fancybox.css" media="screen" />
<!-- Asmselect, deze code wordt gebruikt bij het toevoegen van medewerkers aan een bedrijf -->
<script type="text/javascript" src="../js/jquery.asmselect.js"></script>
<link type="text/css" href="../css/jquery.asmselect.css" rel="stylesheet" />
</head>
有趣的是,当我将一些自制函数放入文件中时,这些函数可以正常工作。
有人出主意吗?