douminfu8033 2010-06-01 09:25
浏览 231
已采纳

在jQuery中调用PHP函数(var)

I'm facing a small problem that I can't solve by myself.

I have this php function:

function intervalo_manha(){
    $que="select id_intervalo,data_15
          from intervalo_manha
          order by id_intervalo";
        $re=mysql_query($que);
        $object.="<select>";
        $object.="<option></option>";
    while(list($id_intervalo, $data_15)=mysql_fetch_row($re))
    {
       $object.= "<option value=\"".$id_intervalo."\">".$data_15."</option>"; 
    }
        $object.="</select>";
return $object;
}

This function return a select with information from database.

I also have this js function:

$(document).ready(function() {
              var destTable = $("#dataTable");
              $("#btnAdd").click(function() {
               var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td></td></tr>");
               $("#dataTable").append(newRow);
                newRow.find('input').autocomplete("get_cols_name.php", {
                    width: 260,
                    matchContains: true,
                    selectFirst: false
                    });
                });
            });

This one will add a new row to my table, and for each new input will "activate" autocomplete. What I want to do is, instead of this:

var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td></td></tr>");

I would like to have something like this:

var newRow = $("<tr style='margin-left:-60px'><td><INPUT type='checkbox' name='chk'/></td><td><INPUT type='text' name='txt[]' id='txt'/></td><td><?php echo intervalo_manha(); ?></td></tr>");

Calling php function directly will return nothing, and I can't do anything. Is there any way to accomplish this?

Thank you

  • 写回答

6条回答 默认 最新

  • dsdxlibt98300 2010-06-02 22:39
    关注

    I solved my problem with a friend's help.

    Basically what we've done.

    We create a div with the "php echo":

    <div id="intervalo-manha"><?php echo intervalo_manha(); ?></div>
    

    Then we've hiden it with css:

    <style type="text/css">
        #intervalo-manha {
            display: none;
        }
    </style>
    

    After this we just called the div at jQuery function:

    var newRow = $("<tr style='margin-left:-60px'>...<td>" + $("#intervalo-manha").html() + "</td></tr>");
    

    I never thought that it could be so easier. :)

    Thank you for everyone who gave me tips and suggestions.

    regards

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置