“表单”中的输入字段类型不适用于Jquery

时间:2013-10-24 15:52:58

标签: php jquery html forms input

我的项目有问题。我有一个行的时间表,可以使用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");
    });

});

我怀疑是:

创建的第一行在小时内完美地工作,输入=“date”:

<td><input type="time" name="hour[0]" placeholder="hour"></td>

但是,在Jquery代码中:

<td><input type="time" name="hour[0]" placeholder="hour"></td>

它不起作用。它不接受类型时间。我尝试过其他类型,比如密码或日期。我认为Jquery不承认这种形式。

请问有人给我解决方案吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您的字符串拼贴有点偏离,name='hour['+countInputs+']'之类的部分应为name='hour["+countInputs+"]',因为您使用"来引用字符串。