我的项目有问题。我有一个带有一行的时间表,其中可以使用 Jquery 动态添加更多行。
代码是:
<?php
session_start();
?>
<html lang="es">
<head>
<meta charset="iso-8859-1">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="rows_management.js"></script>
</head>
<body>
<div id="elements">
<form id="data" action="timetable_processing.php" method="post">
<table border="1" id="table">
<thead>
<tr>
<td>Hour</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
</thead>
<tbody>
<tr class="first-row">
<td><input type="time" name="hour[0]" placeholder="hour"></td>
<td><input type="text" name="subject_mon[0]" placeholder="Subject"><br><input type="text" name="id_user_mon[0]"placeholder="Id_teacher"></td>
<td><input type="text" name="subject_tue[0]" placeholder="Subject"><br><input type="text" name="id_user_tue[0]"placeholder="Id_teacher"></td>
<td><input type="text" name="subject_wed[0]" placeholder="Subject"><br><input type="text" name="id_user_wed[0]"placeholder="Id_teacher"></td>
<td><input type="text" name="subject_thu[0]" placeholder="Subject"><br><input type="text" name="id_user_thu[0]"placeholder="Id_teacher"></td>
<td><input type="text" name="subject_fri[0]" placeholder="Subject"><br><input type="text" name="id_user_fri[0]"placeholder="Id_teacher"></td>
<td class="remove">Remove</td>
</tr>
<input type="hidden" name="year" id="year" value="<?php echo $year ?>">
<input type="hidden" name="class" id="class" value="<?php echo $class ?>">
</tbody>
</table>
<input type="button" id="add" value="Add row" />
<input type="submit" id="submit" value="Submit">
</form>
</div>
<?php
$connection = mysql_connect("localhost", "alonsosjumper", "alonsosjumper") or die('It´s not possible to connect: ' . mysql_error());
echo '<br>OK, all correct<br>';
mysql_select_db("project", $connection) or die('It´s not possible to open the database');
$query= "select id_user, name, surnames from users where user_type='teacher' order by id_user";
$result= mysql_query($query);
echo ' <p>Teachers:</p>
<table border="1" width="auto">
<tr><td>Id_user</td><td>Name</td><td>Surnames</td></tr>';
while($row = mysql_fetch_array($result))
{
echo "<tr><td>".$fila['id_user']."</td><td>".$fila['name']."</td><td>".$fila['surnames']."</td></tr>";
}
?>
</body>
</html>
和:
$(document).ready(function(){
var countInputs = ($(".first-row").length);
$("#add").on('click', function(){
$('#table > tbody:last').after("<tr><td><input type='time' name='hour['+countInputs+']' placeholder='Hour'></td><td><input type='text' name='subject_mon['+countInputs+']' placeholder='Subject'><br><input type='text' name='id_user_mon['+countInputs+']' placeholder='Teacher'></td><td><input type='text' name='subject_tue['+countInputs+']' placeholder='Subject'><br><input type='text' name='id_user_tue['+countInputs+']' placeholder='Teacher'></td><td><input type='text' name='subject_wed['+countInputs+']' placeholder='Subject'><br><input type='text' name='id_user_wed['+countInputs+']' placeholder='Teacher'></td><td><input type='text' name='subject_thu['+countInputs+']' placeholder='Subject'><br><input type='text' name='id_user_thu['+countInputs+']' placeholder='Teacher'></td><td><input type='text' name='subject_fri['+countInputs+']' placeholder='Subject'><br><input type='text' name='id_user_fri['+countInputs+']' placeholder='Teacher'></td><td class='remove'>Remover</td></tr>");
countInputs++;
});
$(document).on("click",".remove",function(){
if (countInputs>1)
{
var parent = $(this).parents().get(0);
$(parent).remove();
countInputs--;
}
else
alert("It´s not possible to remove the last row");
});
});
我的疑问是:
使用 input="date" 创建的第一行在一小时内完美运行:
<td><input type="time" name="hour[0]" placeholder="hour"></td>
但是,在 Jquery 代码中:
<td><input type="time" name="hour[0]" placeholder="hour"></td>
它不起作用。它不接受类型时间。我尝试过其他类型,例如密码或日期,但都没有。我认为 Jquery 无法识别该表单。
有人可以给我一个解决方案吗?
谢谢!