javascript - Codeigniter:在动态文本框/文本区域上生成 id

标签 javascript php jquery html codeigniter

我在动态文本区域上生成 ID 时遇到问题。

这是我的模型:

public function select_fields3($tablename3){
     $this->load->library('table');
     $fields = $this->db->field_data($tablename3['table1']);
     return $fields;
 }

这是我的 Controller :

 public function add_all_inventory(){
    $this->data['title'] = "Add New Inventory";
    $this->load->vars($this->data);
    $table_naming_1 = $_POST['table1'];
    $this->load->view('homeview');

    $select_inv['inventorytype'] = $this->inventory_model->select_tables();
    $this->load->view('inventoryview', $select_inv);

    $select_fields['add_all'] = $this->inventory_model->select_fields3($this->input->post());

    $values_array1 = array('add_all_1' => $select_fields['add_all'],
                           'tablename1' => $table_naming_1);

    $this->load->view('add_all_inventory', $values_array1);

    $this->load->view('footer_view');
}

无需关注 $select_inv,它只是一个引用,以便我可以加载表的字段。这是我的观点:

<div class="row">
<fieldset>
    <form action="" method="POST" id="frm_add_all_inventory" name="frm_add_all_inventory">
    <legend>Add New <input style="border: none; background-color: transparent;" type="text" name="txt_table" id="txt_table" value="<?php echo $tablename1; ?>" readonly/></legend>
            <table style="">
                <?php foreach($add_all_1 as $row) { ?>
                <tr style="">
                    <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
                    <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
                </tr>
                <?php } ?>
                <tr>
                    <td></td>
                    <td></td>
                    <td>
                        <button type="button" class="btn_add_all_inventory btn-success btn-sm"><span class="glyphicon glyphicon-ok"></span>&nbsp;Save</button>
                        <button type="button" class="btn_cancel_all_inventory btn-danger btn-sm"><span class="glyphicon glyphicon-remove"></span>&nbsp;Cancel</button>
                        <button type="button" class="btn_clear_all_inventory btn-warning btn-sm" onclick="document.getElementById('frm_add_all_inventory').reset();"><span class="glyphicon glyphicon-refresh"></span>&nbsp;Clear</button>
                    </td>
                </tr>
             </table>
        </form>
</fieldset>

你看到我的textarea标签在foreach循环内,我想知道如何在这个textarea上生成一个ID。希望你能帮助我。预先感谢您!

最佳答案

你能尝试一下吗?

这就是你想要的吗?

<?php
    $count=0; /* Initialize variable */
    foreach($add_all_1 as $row) {
?>
      <tr style="">
       <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
        <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
       </tr>
<?php 
     echo 'Generated Id: ID'.$count; /*Something Prefix*/
     $count=$count+1; /*Increase the Variable*/
    } 
?>

关于javascript - Codeigniter:在动态文本框/文本区域上生成 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25737137/

相关文章:

php - Magento 1.9 session 文件清除

php - 删除动态生成的文件夹时遇到困难

javascript - Ajax 调用中未找到 Yii2 类

javascript - 如何禁用特殊字符粘贴到文本框中

javascript - Jquery - 制作cookie后隐藏元素

javascript - 更改事件不起作用

javascript - 在重定向之前将 php 函数分配给同一页面内的变量 session 的更好方法

javascript - Typescript中异步函数的返回值

javascript - Primefaces 以编程方式触发的事件触发两次

javascript - 纯 Javascript 作为 Angular 2 服务