1

我的 jQuery 代码不起作用,我找不到原因。代码似乎没问题。

我的html代码

<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');
    });
});
4

2 回答 2

2

如果您想启用提交按钮,请尝试以下 javascript 代码:

$(document).ready(function (){
    $('input[type=file]').change(function(){
        $(this).closest('form').find('[type=submit]').prop('disabled', false);
    });
});
于 2013-03-15T16:23:07.680 回答
1

.next()选择您选择的元素的紧随其后的兄弟,在您的情况下,这将是一个 break ( <br />)。请尝试:

$(this).siblings('input[type=submit]').removeAttr('disabled');

jsFiddle 示例

于 2013-03-15T16:23:43.657 回答