如何在javascript中使用变量php for 2功能?

时间:2014-10-09 02:23:14

标签: javascript php jquery html ajax

所以我想使用2函数java脚本在内容和自动提示时自动添加新列,这个例如编码时自动添加新列的内容http://jsfiddle.net/3jLbm9sp/1/所以当我在第一列中尝试输入时,他将为第一列提供自动建议并添加新列(第二列)并给出自动提示。但我不能这是我的所有编码:

<html>
    <head>
        <form method = "POST" action="text.php" >
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Admin</title>
        <link href="css/inputpo.css" rel="stylesheet">
        <link rel="stylesheet" href="css/jquery-ui.css"/>
        <script src="js/jquery-1.9.1.js"></script>
        <!--For Auto Suggestion -->
        <script src="js/jquery-ui.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            $("#code1").autocomplete({
                source: 'autosuggest.php',
                select:function(event, ui){
                            $('#descrip1').val(ui.item.descrip1);                           
                }
            });
        });
        </script>
        <!--For Auto Add New Colomun-->
        <script type="text/javascript">
        var data = <?php echo json_encode($code1); ?>;
            $txt=new Array();
            $(function(){
                $('#go').on('click',function(){
                    console.log($('form').serialize());
                })

                $('body').on('keydown','.last',function(){
                    $('.last').removeClass('last');
                    $('#go','body').before(
                    '<table><tr><td><input class="last" type="text" id="code1" name="code'+(Number($(this).attr('name').match(/[0-9]+/g))+1)+'" value=""></td>

');
}) })
            

    </head>
    <body>
    <?php
$code1="";
if($_GET) {
$code1      = isset($_POST['code']) ? $_POST['code1'] : '';
$descrip    = isset($_POST['descrip1']) ? $_POST['descrip1'] : '';

}
?>
        <div class="isi">
                <table height="51" border="0" cellspacing="2">
                <tr>
                    <td width="99" align="center" label for="suggestionbox">
                        <div align="center">Code</div></label>
                    </td>
                    <td>
                        <div align="center">Description</div>
                    </td>
              </tr>
              <tr>
                <td>
                <input  class="last"  type="text" id="code1" name='code1' value="<?php echo $code1;?>">
                </td>
                <td>
                <input  class="last"  type="text" id="descrip1" name='descrip1' value="">
                </td>
              </tr>
            </table>
                <input id="go" name="" type="submit" /></td>
        </div>
    </body>
</html>

如果我只使用自动提供它的工作,但无法添加新列,如果我使用添加新列,我无法得到自动建议,当我检查失败功能在这里

type="text" id="code1" name="code'+(Number($(this).attr('name').match(/[0-9]+/g))+1)+'" value="">

如果值为空=&#34;&#34;它的工作是添加新列,以及autosuggestion变量(PHP)的位置是$ code1,所以我尝试写入值=&#34;&#34;&gt;有人知道如何在javascript函数中编写php变量吗?可以使用另一个像ajax,但我不知道如何。

0 个答案:

没有答案