我有一个php函数,它自动完成我的网站的输入,我通过jquery调用它。
<script type="text/javascript">
jQuery(document).ready(function(){
$('#concept_input').autocomplete({source:'search_Concept.php', minLength:1});
});
在另一边,我有一个javascript函数,它在原始输入的下面添加了一个新的输入。
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell3 = row.insertCell(0);
var element3 = document.createElement("input");
element3.type = "text";
element3.id = "concept_input"
element3.name = "concept_input";
cell3.appendChild(element3);
}
我的问题是,我找不到一种方法来传递php函数与javascript创建的新输入我希望有人能帮助我,谢谢!
ID必须是唯一的。
我将这样做(我的更改注释):
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
//determine the existing inputs with the name concept_input
var inputs = $('input[name="concept_input"]')
var cell3 = row.insertCell(0);
var element3 = document.createElement("input");
element3.type = "text";
//give the item a unique ID
element3.id = "concept_input_" + inputs.length
element3.name = "concept_input";
cell3.appendChild(element3);
//use jQuery to add the autocomplete, just like you do at document ready.
$('#concept_input_' + inputs.length).autocomplete({source:'search_Concept.php', minLength:1});
}