Textarea大小适合每行的所有行和限制字符

时间:2015-05-21 23:12:35

标签: php jquery

我有这段代码,我从数据库中获取textarea输出($activities)。一些数据由textarea中的多行组成。如何显示适合数据库中所有行的textarea。目前我正在使用jQuery $('textarea').autoResize();,它只在输入数据时有效,在显示数据时不起作用。它只显示带滚动条的一行。此外,是否可以将每行的字符数限制为30个字符,当它达到限制时它会自动断行?有人能告诉我一个例子吗?

PHP:

<?php

$day = 6;

for($i=1; $i<= $day ;$i++){ 
    echo "<div class='item'>";
    echo "<form class='itineraryForm' id='itineraryForm$i'  method = 'post'>";
    echo "<table>";
    echo "<tr>";
    echo "<th>Time</th>";
    echo "<th>Activities</th>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "<input type='text' class='i_field' name='time[]' value='$time' />";
    echo "</td>";
    echo "<td>";
    echo "<textarea rows='1' class='i_field$i' name='activities[]'>".$activities."</textarea>";
    echo "</td>";
    echo "</tr>";
    echo "</tbody>";
    echo "<input type='image' class='i_save_btn' src='img/save.png' value='SAVE' align='right'/>";
    echo "</table>";
    echo "</form>";
    echo "</div>";
}
?>

的javascript:

$(document).ready(function () {
    $(document).on('click',".i_save_btn",function(e){
        e.preventDefault();
        $.post('inc/process.php', $(this).parents('form').serialize(), function(data) {});
    });
});

1 个答案:

答案 0 :(得分:0)

您在echo "</div>";

之后立即错过了echo "</form>";