我已經看過這個簡單的腳本的所有版本,我無法得到它的工作。JS:添加文本輸入動態工作不
按鈕添加字段,我檢查源代碼,我按一下按鈕,它增加了使用正確的名稱正確的字段=但是當我提交,沒有信息從動態添加領域轉移。
var count = 2;
function addLine() {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
\t var cell3 = row.insertCell(2);
\t var cell4 = row.insertCell(3);
\t var cell5 = row.insertCell(4);
\t cell1.setAttribute("class", "odd");
\t cell2.setAttribute("class", "odd");
\t cell3.setAttribute("class", "odd");
\t cell4.setAttribute("class", "odd");
\t cell5.setAttribute("class", "odd");
\t var input1 = document.createElement('INPUT');
\t input1.setAttribute("type", "text");
\t input1.setAttribute("name", "input" + count + "d1");
\t input1.setAttribute("class", "whtext");
\t cell1.appendChild(input1);
\t cell2.innerHTML = "<input class='whtext' name='input" + count + "d2' type='text'>";
\t cell3.innerHTML = "<input class='whtext' name='input" + count + "d3' type='text'>";
\t cell4.innerHTML = "<input class='whtext' name='input" + count + "d4' type='text'>";
\t cell5.innerHTML = "<input class='whtext' name='input" + count + "d5' type='text'>";
\t document.getElementById("counter").value = count;
\t count++;
}
正如你所看到的,我有兩個不同的版本,我已經試過,用的appendChild,只是添加到innerHTML的。我是JS的新人,所以這讓我難住。
我已經運行的var_dump($ _ POST);並沒有任何JS添加字段顯示。
您可以先做的最好的事情是將它分成諸如createCell(),createInput()之類的函數。這樣你的代碼就會更有條理,更容易改變,這不是最好的方式,我可以爲你的問題提供一個答案,但我不會真正幫助你。 – ocespedes
我懷疑input1.setAttribute(「名」,...)不工作的香港專業教育學院通過使用setAttribute看到情況下,瀏覽器不會讓你設置的名稱..具有u嘗試,而不是DOM方法作爲測試的innerHTML? 也是什麼瀏覽器? –
我們需要HTML代碼! –