Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

javascript - How to handle onchange event on input type=file in jQuery?

The code is:

<input ID="fileUpload1" runat="server" type="file"

The following works fine:

<input onchange="javascript:alert('hola');" ID="fileUpload1"  runat="server" type="file"

I'd like to get this result using jQuery, but that doesn't work:

$('#fileUpload1').change(function (e) {
    alert("hola");
});

I am missing something? (Edit: Yes I missed include the *.js file.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Demo : http://jsfiddle.net/NbGBj/

$("document").ready(function(){

    $("#upload").change(function() {
        alert('changed!');
    });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...