我如何使用JavaScript来增长HTML表单? [英] How do I use JavaScript to grow an HTML form?

查看:103
本文介绍了我如何使用JavaScript来增长HTML表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的Web应用程序,用户可以使用该应用程序创建附加文件的消息。

多个html文件输入JavaScript链接http://img38.imageshack.us/img38/4474/attachments.gif



这个附加文件链接还没有工作。它应该在每次单击时向表单添加一个额外的文件输入控件。



我需要JavaScript方法 addanotherfileinput()来替换点击anchor:

 < a href =#id =attachlinkonclick =addanotherfileinput>附加附加文件< / A> 

使用这个新的表格行,文件输入和锚点:$ b​​
$ b

 < input type =filename =Attachment1id =Attachment1class =textinput/> 
< / td>
< / tr>
< tr>
< td>< / td>
< td>
< a href =#id =attachlinkonclick =addanotherfileinput>附加其他文件< / a>

同时也增加数字:附件2,附件3,附件4等。

我该怎么做?

解决方案

您可以使用DOM动态插入文件输入

  var myTd = / *从dom * / 

var myFile = document中获取td。的createElement( 'INPUT');
myFile.type ='文件'
myFile.name ='文件'+ i; //我是一个var存储在某处
+++;

myTd.appendChild(myFile);

或者您可以使用这个



< a href =http://developer.yahoo.com/yui/examples/uploader/uploader-simple-button.html =nofollow noreferrer> http://developer.yahoo.com/yui/examples/uploader /uploader-simple-button.html


I'm creating a simple web application with which a user may author a message with attached files.

multiple html file inputs with javascript link http://img38.imageshack.us/img38/4474/attachments.gif

That "attach additional files" link does not yet work. It should add an additional file input control to the form each time it's clicked.

I need a JavaScript method addanotherfileinput() to replace the clicked anchor:

        <a href="#" id="attachlink" onclick="addanotherfileinput">attach additional files</a>

With this new table row, file input, and anchor:

        <input type="file" name="Attachment1" id="Attachment1" class="textinput" />
    </td>
</tr>
<tr>
    <td></td>
    <td>
        <a href="#" id="attachlink" onclick="addanotherfileinput">attach additional files</a>

And also increment the number: Attachment2, Attachment3, Attachment4, etc.

How can I do this?

解决方案

You could use the DOM to dynamically insert the file inputs

var myTd = /* Get the td from the dom */

var myFile = document.createElement('INPUT');
myFile.type = 'file'
myFile.name = 'files' + i; // i is a var stored somewhere
i++;

myTd.appendChild(myFile);

OR you can use this

http://developer.yahoo.com/yui/examples/uploader/uploader-simple-button.html

这篇关于我如何使用JavaScript来增长HTML表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆