开发者

Open html file dialog with jquery

开发者 https://www.devze.com 2023-03-18 04:08 出处:网络
I am trying to open input file dialog after clicki开发者_JAVA百科ng on link. I made a script with jquery. But I also want to avoid opening this dialog after clicking on input file:

I am trying to open input file dialog after clicki开发者_JAVA百科ng on link. I made a script with jquery. But I also want to avoid opening this dialog after clicking on input file:

            $('#link').click(function(event) {
                event.preventDefault();
                $('#id_default_image').click();
            });
            $('.file_input').click(function(event) {
                event.preventDefault();
            });

Now when I click on link or input file dialog does not show. Can I check if user clicks on link or on input and show dialog or not?


You can use global flag for this, and raise it when clicking the link.

Code will now be:

$('#link').click(function(event) {
    event.preventDefault();
    window["link_clicked"] = true;
    $('#id_default_image').click();
    window["link_clicked"] = false;     
});

And to check the flag:

$('.file_input').click(function(event) {
    if (window["link_clicked"]) {
        alert("you clicked the link");
    }
    //event.preventDefault();
});

Live test case: http://jsfiddle.net/trG5D/1/

0

精彩评论

暂无评论...
验证码 换一张
取 消