Home  >  Article  >  Web Front-end  >  How to use trigger method to pop up file selection dialog box without clicking file type input

How to use trigger method to pop up file selection dialog box without clicking file type input

php中世界最好的语言
php中世界最好的语言Original
2018-02-10 09:40:493016browse

This time I will show you how to use the trigger method to pop up the file selection dialog box without clicking the file type input, and how to use the trigger method to pop up the file selection dialog box without clicking the file type input. Notes What are they? Here are actual cases. Let’s take a look.

You can use the trigger method. There is no native trigger function in javascript. You can write one yourself, or you can directly use the jquery implementation:

var button1 = document.getElementById("button1");  
    var button2 = document.getElementById("button2");  
    button1.onclick = function(){alert("button1");trigger(button2,"onclick");}  
    button2.onclick = function(){alert("button2");}  
    function trigger(ele,event)   
    {ele[event]();}

Also you can A simpler way is to cover the image or hyperlink or other div to be clicked with the input, and then set the input to be completely transparent, so that when you click on the image, you actually click on the input, as follows:

<div class="ps-image" style="width:300px;height:300px;border:0px sold red; background:url(&#39;/images/ps.png&#39;)">  
    <input type="file" id="file" style="filter:alpha(opacity=0);opacity:0;width:100%;height:100%;"/>  
    </div>

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

What are the symbols that mark text comments in Html

How to set and hide other attributes in a tag Only display pictures

#How to implement HTML-like command line interface

The above is the detailed content of How to use trigger method to pop up file selection dialog box without clicking file type input. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn