-1

I am struggling with javascript these days, I want to create dynamic add/remove element using java script and i came across following site, but following example doesn't working for me do you know what is wrong in example?

Adding and Removing Elements on the Fly Using JavaScript

I am having issue in following line, which i found using chrome developer tool

var html = '<input type="file" name="uploaded_files[]" /> ' +
               '<a href="" onclick="javascript:removeElement('file-' + fileId + ''); return false;">Remove</a>';

Here is the screenshot of google chrome developer tool

enter image description here

4

3 回答 3

2

You need to escape your quotes.

var html = '<input type="file" name="uploaded_files[]" /> ' + '<a href="" onclick="javascript:removeElement(\'file-\' + fileId + \'\'); return false;">Remove</a>';

于 2013-05-30T14:52:18.850 回答
0

You might need to escape those single quotes.

 onclick="javascript:removeElement(\'file-\' + fileId + ''); return false;">Remove</a>';

That is what I would try.

You want the quotes to be there when you add the text. You will also have a have files that are named like this

  file-1
  file-2
于 2013-05-30T14:50:35.033 回答
0

Did you add addElement('files', 'p', 'file-' + fileId, html);

At the end of addFile()?

We can't do anything for you if we don't have more information about your 'problem'

Be more explicit in your description.

于 2013-05-30T15:02:46.823 回答