I've replaced your id attributes with name attributes, to me the [] at the end is something you'd only do with name, and duplicating ids is not a good thing (copying rows, etc). You don't really need ids there anyway.
Also rather than using the table row/column interface, I've changed it to use the "generic html" interface.
An answer to your actual question is to store the current segment in a variable and increment it when you're creating a new row.
// store the last segment number in a global variable
var lastSegment = 1;
function addRow(tableID) {
var tbody = document.querySelector("#" + tableID + " tbody");
var rows = tbody.querySelectorAll("tr");
if(rows.length < 10){ // limit the user from creating too many segments
// copy the first TR of the table
var newRow = rows[0].cloneNode(true);
// increment the last segment number and apply it to the new segment[] field
newRow.querySelector("input[name='segment[]']").value = ++lastSegment;
// add the new row
tbody.appendChild(newRow);
} else {
alert("Maximum Number of Segments is 10.");
}
}
<h1>Table Example
<input type="button" value="Append Segment" onClick="addRow('dataTable')" />
</h1>
<table id="dataTable">
<tbody>
<td><input type="checkbox" name="chk[]" unchecked></td>
<td><label>Segment: </label></td>
<td><input type="text" name="segment[]" value ="1"></td>
<td><label>Direction: </label></td>
<td><select name="direction[]">
<option>...</option>
<option>Horizontal</option>
<option>Vertical</option>
</select></td>
</tbody>
</table>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…