【问题标题】:Create a table dynamically , number of row depend of select number动态创建表,行数取决于选择数
【发布时间】:2015-01-28 18:05:20
【问题描述】:

我是 jquery 的初学者...对不起

我需要根据我选择的行数动态创建一个表


index.php

<div class="input-append" >
<span class="add-on">Nombre de TGBT</span>
 <?
$selected = '';
echo '<select name="nb_tgbt"  id="nb_tgbt" size="1">',"\n";
for($i=0; $i<=10; $i++)
{
$selected = 'selected="selected"';
echo "\t",'<option value="'.$i.'"'.$selected.'>'.$i.'</option>',"\n";
$selected='';
 }
echo '</select>',"\n";       
?>
 </div>

我通过 POST 方法将值发送到页面“getvalue.php”

getvalue.php 的代码是:

<?php

$tabletgbt='';
$tabletgbt=$tabletgbt.'<form>
                         <fieldset> 
                             <div class="input-append">';

for($i=1; $i<=$_POST['id']; $i++)
{
$tabletgbt=$tabletgbt.'<div><span class="add-on">Nom TGBT'.$i.'</span>       
<input  id="tgbtname'.$i.'" type="text" placeholder="Nom du TGBT '.$i.'"/>  

</div>';
}

$tabletgbt=$tabletgbt.'
                           </div>
                     </fieldset>
                   </form>';
return $tabletgbt;



$i='';
?>

如何在我的 index.php 上动态显示返回数据(html 代码),请在更改时动态显示

问候

【问题讨论】:

  • 我没有看到任何使用 AJAX 的代码,您是在问我们如何使用 AJAX 吗?
  • ^ 请将其添加到您的问题 OP 中 - 大块代码在 cmets 中不是很可读。谢谢!

标签: javascript php jquery


【解决方案1】:

这是我使用的 ajax 代码:

Hello,  this is the ajax code i used:
   <script> 
    $(document).ready(function(){ 
    $('#nb_tgbt').change(function(){ 
    var nbretgbt_id = $('#nb_tgbt').val(); 
    if(nbretgbt_id != 0) { 
    $.ajax({ type:'post', url:'getvalue.php', data:{id:nbretgbt_id}, cache:false, success: function(returndata){
  $('#tablename_tgbt').html(returndata); 
    } 
});
} 
}) 
}) 
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多