开发者

Force click event on input file or open choose file window

I have a form in my HTML with field.

I'd like to show the file selection window when the user clicks somewhere else开发者_开发技巧 (for example, an image on other part of the screen). The reason I want to do this is that I have a form with many fields, posting to some action "x", and the file selection form on other part of screen, submiting to action "y"

<form action="x">
   <input type="text" name="field1">
   <input type="text" name="field2">
   <input type="text" name="field3">
   <img src="select_file.png" onclick="//triggers file selection on other form">
   <input type="text" name="field4">
   <input type="text" name="field5">
</form>

<form action="y">
  <input type="file" name="myfile">
</form>

Is there any other way to do this?


 $("img").click(function(){
    $("input[name=myfile]").trigger('click');
 });

Demo. Click on the envelope image.

Edit: Giving ID's on the each of input fields will make the code more readable and "good."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜