0
JS를 사용하여 테이블 행을 복제합니다. 양식 요소는 복제 될 때 숫자가 첨부됩니다. 나는 잘 작동한다.클래스 예외가있는 테이블 행 복제
내 문제는 대부분의 필드의 값을 지우고 싶지만 특정 클래스가있는 값은 지울 수 없습니다.
HTML
<div class="add_rec_container" id="fuel_stop" style="display:none;"><!--open #fuel_stop-->
<p class="label">Enter Fuel Stop:</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="fuel_stop_table" class="fuel_data">
<tbody>
<tr>
<td><select name="data_fuel_state1" id="data_fuel_state1" class="state_menu">
<option value="AZ">AZ</option>
<option value="CA" selected="selected">CA</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="OR">OR</option>
<option value="UT">UT</option>
</select>
</td>
<td><input type="tel" name="data_total_gal1" id="data_total_gal1" class="total_gal_field" title="Gallons" placeholder="Gallons"/></td>
<td><input type="checkbox" name="data_yard1" id="data_yard1" class="yard_check" value="y" onclick="disablePPG(this);"/> Yard
</td>
<td>$ <input type="tel" name="data_price1" id="data_price1" class="price_field" title="PPG" placeholder="PPG" /></td>
</tr>
</tbody>
</table>
<a id="add_fuel_row" class="add_btn">+ State</a>
</div><!--close #fuel_stop-->
<input type="submit" name="Submit" class="send_button" value="Send"/>
</form>
</div><!--close .record_entry_container-->
JS
입력이 "yard_check"의 클래스가있는 경우<!-- Inset Table Row --Fuel -->
$(document).ready(function($)
{
// trigger event when button is clicked
$("a#add_fuel_row").click(function()
{
// add new row to table using addTableRow function
addTableRow($("table#fuel_stop_table"));
// prevent redirecting
return false;
});
// function to add a new row to a table by cloning the last row
function addTableRow(table)
{
// clone the last row in the table
var $tr = $(table).find("tbody tr:last").clone();
// get the name attribute for input and select fields
$tr.find("select, input").val('').attr("name", function()
{
// break the field name and it's number into two parts
var parts = this.id.match(/(\D+)(\d+)$/);
// create a unique name (+1 scheme for now)
return parts[1] + ++parts[2];
// repeat for id attributes
}).attr("id", function()
{
var parts = this.id.match(/(\D+)(\d+)$/);
return parts[1] + ++parts[2];
});
// append the new row to the table
$(table).find("tbody tr:last").after($tr);
};
});
은 내가 값을 취소하고 싶지 않아요. 즉 체크 박스는 값 = y로 유지되어야합니다.
감사합니다.
를 사용하여 확인 속성을 제거 제외하고는 동일한 작업을 수행, 체크 박스를 들어
사용합니다. 내가 붙어있는 곳은 값에 대한 조건이 다른 여러 양식 항목에 대해이를 수행하는 방법입니다. – macericpet
예를 들면. 선택 메뉴와 텍스트 필드는 값을 지우지 만 체크 상자는 값을 유지합니다. – macericpet
체크 박스에 값을 유지 시키려면 체크 된 속성을 그대로 두는 것이 좋겠습니까? – shubniggurath