jQuery/Javascript代码在Chrome和Firefox中不起作用
我想使用jQuery/Javascript动态添加表行,我使用了以下代码,但在Chrome中不起作用。有什么帮助吗jQuery/Javascript代码在Chrome和Firefox中不起作用,javascript,jquery,Javascript,Jquery,我想使用jQuery/Javascript动态添加表行,我使用了以下代码,但在Chrome中不起作用。有什么帮助吗 function AddTextBoxes(label,parameter, paraId) { strCode += "<tr><td>"; strCode += "<label id='" + label + "1'>" + label + "</label></td><td>"; strCod
function AddTextBoxes(label,parameter, paraId) {
strCode += "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId +" value="+parameter.minValue + "-" + parameter.maxValue+ ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
}
函数addTextBox(标签、参数、paraId){
strCode+=“”;
strCode+=“”+标签+“”;
strCode+=“”;
$(“#”+paraId.attr('value',parameter.minValue+“-”+parameter.maxValue);
$(“#”+paraId.attr('text',parameter.minValue+“-”+parameter.maxValue);
strCode+=“”;
}
您需要在函数中附加未执行的strcode内容
此外:-
您需要在此行(函数开头)之前添加var strCode='
:-
strCode+=”;
这是需要修改的代码。此外,还需要对生成的字符串执行一些操作。例如,将其附加到body。(未经测试)
函数addTextBox(标签、参数、paraId){
var strCode=“”;
strCode+=“”+标签+“”;
strCode+=“”;
$(“#”+paraId.attr('value',parameter.minValue+“-”+parameter.maxValue);
$(“#”+paraId.attr('text',parameter.minValue+“-”+parameter.maxValue);
strCode+=“”;
document.body.innerHTML+=strCode;
}
您需要初始化strCode并将其追加到表中。范例
$('#tableId').append(strCode);
更新代码:
function AddTextBoxes(label, parameter, paraId) {
var strCode = '';
strCode += "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId + " value=" + parameter.minValue + "-" + parameter.maxValue + ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
$('#tableId').append(strCode); // Change tableId with your table id
}
函数addTextBox(标签、参数、paraId){
var strCode='';
strCode+=“”;
strCode+=“”+标签+“”;
strCode+=“”;
$(“#”+paraId.attr('value',parameter.minValue+“-”+parameter.maxValue);
$(“#”+paraId.attr('text',parameter.minValue+“-”+parameter.maxValue);
strCode+=“”;
$('#tableId').append(strCode);//使用表id更改tableId
}
var myRow=“我的行”;
$(“#myTableId”).append(myRow);
您是否在函数外部声明了var strCode=''
?您需要附加strCode的内容。@Geek此函数只创建一个包含一些HTML的字符串,在Chrome中“它不工作”的确切含义是什么?实际上,我的代码在IE中工作正常,但在Chrome或Mozilla中工作不正常。我使用jquery将strCode添加到我的div中。
$('#tableId').append(strCode);
function AddTextBoxes(label, parameter, paraId) {
var strCode = '';
strCode += "<tr><td>";
strCode += "<label id='" + label + "1'>" + label + "</label></td><td>";
strCode += "<input type='text' id=" + paraId + " value=" + parameter.minValue + "-" + parameter.maxValue + ">";
$("#" + paraId).attr('value', parameter.minValue + "-" + parameter.maxValue);
$("#" + paraId).attr('text', parameter.minValue + "-" + parameter.maxValue);
strCode += "</td></tr>";
$('#tableId').append(strCode); // Change tableId with your table id
}
var myRow="<tr><td>my row</td></tr>";
$("#myTableId").append(myRow);