我的jQuery代码不工作,我找不到原因。代码似乎没问题。
My html code
<html>
<head>
<title>Learning Jquery</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<input type="file">
<br />
<input type="submit" disabled="disabled">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="myjquery.js"></script>
</body>
</html>
javascript代码
$(document).ready(function (){
$('input[type=file]').change(function(){
$(this).next().removeAttr('disabled');
});
});
如果你想启用提交按钮,那么试试下面的javascript代码:
$(document).ready(function (){
$('input[type=file]').change(function(){
$(this).closest('form').find('[type=submit]').prop('disabled', false);
});
});
.next()
选择您所选择的元素的紧跟其后的兄弟元素,在您的情况下将是break (<br />
)。试试相反:
$(this).siblings('input[type=submit]').removeAttr('disabled');
<<p> jsFiddle例子/strong>