duanqing2209 2011-07-14 16:09
浏览 61
已采纳

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

Hi im using codeigniter PHP with jquery javascript function to create a textbox for time which is formatted.

I want the jquery function to add my textbox to the row of other textboxes instead of adding them to the bottom of the page.

Picture --> http://i.imgur.com/K9PiT.jpg

Here is my php file. It is messy I know but I am new to all of this.

        <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

Thanks

  • 写回答

1条回答 默认 最新

  • dongyuan8312 2011-07-14 16:59
    关注

    You are appending it o body!! Place an empty div with an id where you want to add this text box.

    Then for that div

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

    or append to that div

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件