0

嗨,我正在尝试在按钮单击上生成表格行,但我的问题是组合框,它从 mysql 数据库加载数据,任何人都可以帮助我如何在 mysql 中使用 javascript 这是我的 javascript 代码

<script language="javascript" type="text/javascript">
                        var i=1;
                        function addalRow()
                        {
                            var tbl = document.getElementById('alimtable');
                            var lastRow = tbl.rows.length;
                            var iteration = lastRow - 1;
                            var row = tbl.insertRow(lastRow);

                            var firstCell = row.insertCell(0);
                            var el = document.createElement('input');
                            el.type = 'text';
                            el.name = 'alimname_' + i;
                            el.id = 'alimname_' + i;
                            el.size = 40;
                            el.maxlength = 40;
                            firstCell.appendChild(el);

                            var secondCell = row.insertCell(1);
                            var el2 = document.createElement('input');
                            el2.type = 'text';
                            el2.name = 'alimmob_' + i;
                            el2.id = 'alimmob_' + i;
                            el2.size = 13;
                            el2.maxlength = 13;
                            secondCell.appendChild(el2);


                            var thirdCell = row.insertCell(2);
                            var e13 = document.getElementsByName('qabil')[0]; 
                            e13.setAttribute('name',e13.getAttribute('name')+'_'+                 
                                   i);//change the select's name 
                            thirdCell.appendChild(e13);

                            // alert(i);
                            i++;
                            makhtab.r.value=i;
                            //  alert(i);
                        }
                    </script>

这是我的表格代码

<table border="1px" id="alimtable" size="100px" cellspacing="0" cellpadding="2">
<tr>
<td><strong>Muallim Name</strong></td>
<td><strong>Mobile</strong> </td>
<td><strong>Qabiliyat</strong> </td>
</tr>
<tr>
<td><input name="alimame_0" type="text" id="zimname_0" size="40" maxlength="20" /></td>
<td><input name="alimmob_0" type="text" id="zimmob_0" size="13" maxlength="20" /></td>
<td><select id="qabil" name="qabil" class="element text large" style="font-size:14px;"/>
<option value=""></option>
<?php
$result = mysql_query("SELECT code, `name` from qabiliyat ") or die(mysql_error());
 while ($qab = mysql_fetch_array($result)) {
echo "<option value='$qab[code]'>$qab[name]</option>";
 }
?>
</select></td>
</tr>
</table>
<input type="button" value="Add" onclick="addalRow();" /><input name="h" type="hidden"  id="r" value="1" />
4

2 回答 2

0
$("#addBox").click(function () {
var newDD = $("<select/>");
$(newDD).append("<option>Option 1</option>");
$(newDD).append("<option>Option 2</option>");
$("#myBox").append(newDD);
});

<div id="myBox"></div>
<input type="button" id="addBox" value="Add" />
于 2013-01-28T07:41:10.390 回答
0

请在onclick中调用ajax函数............

我在这里添加了一些示例....

<script type='text/javascript'>

    //AJAX function
    function startAjax() {
      $.ajax({
        type: "POST",
        url: "test.php",
        data: "name=name&location=location",
        success: function(msg){
          alert( "Data Saved: " + msg );
        }
      });
    }

    //Call AJAX:
    $(document).ready(startAjax);

<button onclick="startAjax();">Test</button>

http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/399114/call-ajax-onclick

于 2013-01-28T07:46:31.233 回答