我有需要必须添加一个动态行的表中的HTML表格添加动态行。我设置了4行的限制,这将根据表的用途而改变。不能似乎使用jQuery
我很困惑,为什么我添加行心不是工作。我确定它可能是非常简单的东西,但我真的需要解决这个问题。请解决方案建议
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
<!--<script src="addrow.js" language="Javascript" type="text/javascript"></script>-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"> </script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"> </script>
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css">
<script>
$(function() {
$('.date-picker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
}
});
});
</script>
<script type='text/javascript'>
var counter = 1;
var limit = 4;
jQuery('a.addrow').click(function(event){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}else{
event.preventDefault();
counter++;
var newRow = jQuery('<tr><td><input type="text" name="' +
counter + '"/></td><td><input type="text" name="' +
counter + '"/></td><td><input type="text" name="' +
counter + '"/></td><td><input type="text" name="' +
counter + '"/></td><td><input type="text" name="' +
counter + '"/></td><td><input type="text" name="' +
counter + '"/></td></tr>');
jQuery('table.history').append(newRow);
}});
</script>
</head>
<html>
<body>
<style>
.ui-datepicker-calendar {
display: none;
}
</style>
<table width="100%">
<tbody>
<tr>
<td colspan="4" width="100%">
<h1>title</h1>
<p>some content</p>
</td>
</tr>
</table>
<table class="history" width="100%">
<tr><td>Dates(Months & Year)</td></tr>
<tr><td>From</td><td>To</td><td colspan="2">NAME - Company/ College/ Job Centre/ Armed Services</p>
</td><td colspan="2">Address</td></tr>
<tr>
<td>
<input name="startDate" id="startDate" class="date-picker" />
</td>
<td>
<input name="toDate" id="toDate" class="date-picker" />
</td>
<td>
<input type="text" name="first_name" />
</td>
<td>
<input type="text" name="last_name" />
</td>
<td>
<input type="text" name="first_name" />
</td>
<td>
<input type="text" name="last_name" />
</td>
</tr>
</table>
<a href="" title="" class="addrow">Add row</a>
为什么你使用'jquery.js'的多个版本?即'jQuery的1.7.js' /'1.4.1/jquery.js'而__your代码works__ – Satpal
这似乎为我工作得很好:https://jsfiddle.net/m49g53eq/你能生产出[MCVE]证明您遇到的问题(或者说,最起码定义“不工作”) – Jamiec
我复制它小提琴,它的工作。只是我只加一个'jQuery' [小提琴](https://jsfiddle.net/jo_Geek/bxcmw8j9/) –