HTML使用javascript、ajax、jquery更改内容
我的phtml文件中有一个表HTML使用javascript、ajax、jquery更改内容,javascript,php,Javascript,Php,我的phtml文件中有一个表 <table width="700" class="detais" cellpadding="10px;"> <tr><td></td><td></td></table> 我还有一个下拉列表,在更改这个下拉列表时,它将调用一个javascript,它是 function filterbyaptno(){ var idno = document.getElementBy
<table width="700" class="detais" cellpadding="10px;">
<tr><td></td><td></td></table>
我还有一个下拉列表,在更改这个下拉列表时,它将调用一个javascript,它是
function filterbyaptno(){
var idno = document.getElementById("aplist").value;
$.ajax({
url: 'address',
type: 'POST',
data:"idno="+idno,
success:function(result) {
var numRecords = parseInt(result.rows.length);
if(numRecords>0)
{
for(var i = 0; i<numRecords;i++)
{
var html ='<div class="support"><table><tr> <td>'+result.row[i].firstname+'</td>
+'<td>'+result.rows[i].advice+'</td>'
+'<td>'+result.rows[i].customdata+'</td><tr></table></div>'
}
$('.detais').replaceWith(html);//am trying to change the table content
}
});
}
函数filterbyaptno(){
var idno=document.getElementById(“aplist”).value;
$.ajax({
url:'地址',
键入:“POST”,
数据:“idno=“+idno,
成功:函数(结果){
var numRecords=parseInt(result.rows.length);
如果(numRecords>0)
{
对于(var i=0;i当您循环结果时,您可以:
var html = ..
它将替换html
变量中已有的内容
在for循环外声明var html
&始终在循环内追加(html+=…
)
您可能还希望在循环外部设置容器
,只在循环内部添加行。您在for
循环的每个迭代中分配html
变量的值,这意味着在每个迭代中,您将用新值替换以前的值,而不是连接以前的值和新值
将代码修改为如下所示:
if (numRecords > 0) {
var html = '';
for (var i = 0; i < numRecords; i++) {
html += '<div class="support"><table><tr> <td>' + result.row[i].firstname + '</td>' + ' < td > ' + result.rows[i].advice + ' < /td>' + '<td>' + result.rows[i].customdata + '</td > < tr > < /table></div > '
}
$('.detais ').replaceWith(html); //am trying to change the table content
}
if(numRecords>0){
var html='';
对于(变量i=0;i'+结果.行[i].建议+''+''+结果.行[i].自定义数据+''
}
$('.detais').replaceWith(html);//我正在尝试更改表内容
}
这是你兄弟的一个很好的帮助。如果我单击一个结果并尝试查看另一个结果,我不知道为什么下拉结果不会改变。@Indira you replace$(“.detais”)
在第一次单击中添加内容,因此您需要确保在下一次单击时添加一个带有classdetais
的新元素以替换,例如
如果这不是问题所在,您需要发布一个带有相关代码的新问题。