alt text

Where is the mistake? If s = 'asdfasdf', then inserts without problems, but does not want to. Here is the code:

function add() { n_i--; i2=n_i+1; id_='stroka_'+n_i; alert(id_); var s ='<tr id="stroka_'+i2+'"> <td style="border-bottom:inherit"><input type="checkbox" name="checkbox" id="checkbox" /></td> <td align="center" id="family'+id+'" onclick="redact(\'family'+id+'\',\''+id+'\')">'+family_y+'</td> <td align="center" id="name'+id+'" onclick="redact(\'name'+id+'\','+id+')">'+name_y+'</td> <td align="center" id="otchestvo'+id+'" onclick="redact(\'otchestvo'+id+'\','+id+')">'+otchestvo+'</td> <td align="center" id="family_y'+id+'" onclick="redact(\'family_y'+id+'\','+id+')"></td> <td align="center" id="name_y'+id+'" onclick="redact(\'name_y'+id+'\','+id+')"></td> <td align="center" id="opisanie'+id+'" onclick="redact(\'opisanie'+id+'\','+id+',0,true)"></td> <td align="center" id="god'+id+'" onclick="redact(\'god'+id+'\','+id+')"></td> <td align="center" id="mesto'+id+'" onclick="redact(\'mesto'+id+'\','+id+')"></td> <td id="delete_"'+id+' class="delete" onclick="delete_('+id+',this);" onmouseover="this+style+cursor=\'pointer\'"><hr width="20px"></td> </tr>'; $('#'+id_).before(s); n_i=n_i+2; } 

    3 answers 3

    Javascript is not php, in it such line breaks do not work. Write all in one line or through s += '...';

    • yes it did =) everything worked - Eugene536

    In ES-2015, you can do such transfers, all you need to do is add 'use strict'; to the top of the code 'use strict'; and replace "" with ``

     Var s = `<h1> Теперь ошибки не будет </h1>` 

    And instead

     Var s = "<tr id='stroka_"+i2+"'>"; 

    Can do

     Var s = `<tr id='stroka_${i2}'>`; 

      And if you try this:

       var s="<tr id='stroka_"+i2+"'>"; 

      Double quotes are external and single quotes for tag values.

      And more:

      For multiline operators to work as they should - the line break can be indicated with a backslash "\"

      Javascript structure

      • not, with should be equal to all the text that is on top! - Eugene536
      • I understood, I just didn’t fix everything) - Leshij_2005
      • how to delete a question? - Eugene536
      • You can close it, or accept the answer) - Leshij_2005