JavaScriptを使用して、以下にあるまったく同じ要素を追加しようとしています。ここで見つかったすべてのソリューションを試しましたが、要素をエコーしようとしましphp echo
たが、うまくいきませんでした。入力名などを変更する必要はありません。単にそのボタンをクリックしてテーブルに別の行を追加するだけです。
要素は次のとおりです。
<tr>
<td><input type="text" name="links"></td>
<td><input type="text" name="keywords"></td>
<td><input type="text" name="violationtype"></td>
<td><input type="submit" id="last" class="button" value="Add another line" onclick:"addField();"></td>
</tr>
私は本当に何でもしていますが、外部参照(jqueryなど)なしでシステムを維持していたので、javascriptが欲しいのですが、現時点ではどんな提案も受け付けています。私は次のコードでそれをやってみました:
function addFields() {
var number = document.getElementById("last").value;
var html = '<tr>' +
'<td><input type="text" name="links"></td>' +
'<td><input type="text" name="keywords"></td>' +
'<td><input type="text" name="violationtype"></td>' +
'<td><input type="submit" id="last" class="button" value="Add another line" name="line" onclick:"addField();"></td>';
number.appendChild(html);
}
しかし、それは何もしないようです。どの入力が最後であるかをより適切に把握してコードを処理する必要があると思いますが、id="last"
それを行う方法がわかりません。