开发者

How do I appendChild a file upload field with i++?

开发者 https://www.devze.com 2023-03-20 00:21 出处:网络
I im creating a javascript file using addElemend and childAppend to add a new Ive written the code here http://jsfiddle.net/faYMH/18/

I im creating a javascript file using addElemend and childAppend to add a new

Ive written the code here http://jsfiddle.net/faYMH/18/

But for some reason it isnt working. If I replace the file 开发者_StackOverflowupload field within the innerhtml with a simple it does work!

Can anyone spot the problem / put in some input how to accomplish what i want?

Thanks!

Jonah


There's a few things wrong with that.

JSFiddle problems

First of all, you still have the framework settings set to "onLoad" and "Mootools". You'll want it to be one of the "no wrap" options and "No-Library (pure JS)". Secondly, you're putting the script in a script tag in the HTML pane. There's a JavaScript pane specifically for JavaScript.

JavaScript problems

You have some inline HTML in your JavaScript:

newDiv.innerHTML = "<input type="file" name="file1 + i++" />";

You're using double quotes (") for your JavaScript string as well as inside the HTML. Try using single quotes for the JavaScript string delimiters, like this:

newDiv.innerHTML = '<input type="file" name="file1' + (i++) + ' />';

The HTML inside the string is also not valid. It will try to generate HTML like this:

<input type="file" name="file10 />

There's no closing quote. Fix that:

newDiv.innerHTML = '<input type="file" name="file1' + (i++) + '" />';

You might also want to remove the stray 1, though it doesn't break the script.

Result

Here it is, after these changes and a few more.

0

精彩评论

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