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()選択した要素の直後の兄弟を選択します。この場合、これはブレーク ( <br />) になります。代わりに試してください:

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

jsFiddle の例

于 2013-03-15T16:23:43.657 に答える