如何使用jquery将文本框添加到分割区域

How to add textboxes to a divved area using jquery

本文关键字:添加 分割 区域 文本 何使用 jquery      更新时间:2023-09-26

Hi-im使用带有jquery javascript函数的codeigniter PHP创建格式化的时间文本框。

我希望jquery函数将我的文本框添加到其他文本框的行中,而不是将它们添加到页面底部。

图片-->https://i.stack.imgur.com/gFO0w.jpg

这是我的php文件。我知道这很混乱,但我对这一切都很陌生。

        <script type="text/javascript"> var i = 0; </script> 
<?php
        for ($i=0; $i< 20; $i++)
        {

?>
   <script type="text/javascript">     
         var input = $("<input>", { //this bit will be removed in the form
                name: 'time'+i,
                val: '00:00:00',
                maxlength: '8',
                size: '5'
            });
            i++;
            input.click(function() {
                $(this).prop({
                    selectionStart: 0,
                    selectionEnd: 0
                });
            }).keydown(function() {
                var sel = $(this).prop('selectionStart'),
                    val = $(this).val(),
                    newsel = sel === 2 ? 3: sel;
                    newsel = sel === 5 ? 6: newsel;
                $(this).val(val.substring(0, newsel) + val.substring(newsel + 1))
                .prop({
                    selectionStart: newsel,
                    selectionEnd: newsel
                });
            });
            $('body').append(('#timearea_DIV').html());
         </script>
            <?php
      echo '<div id="timearea"></div> //THIS IS WHERE THE jquery generated textboxes must go!';
    //the event itself
            echo form_input ('event'.$i , set_value ('event'.$i)); 
    //supplies used
            echo form_input ('supplies'.$i, set_value ('supplies'.$i)); 
    //what is the manufacturer
            echo form_input ('manufacturer'.$i, set_value ('manufacturer'.$i));
    //quantity
            echo form_input ('quantity'.$i, set_value ('quantity'.$i));
    //was the event successful?
            echo form_dropdown ('success'.$i, $yesno , set_value ('success'.$i)); 
    //comment if necessary
            echo form_input ('comment'.$i , set_value ('comment'.$i)); 
     echo '<br/>';
    }
        //end of for loop

感谢

您正在将其附加到正文中!!在要添加此文本框的位置放置一个id为的空div。

那么对于这个div

(#divid).html('text box you want to add')

append到该div