我正在尝试使用jQuery动态创建类似以下HTML表格:
<table id='providersFormElementsTable'>
<tr>
<td>Nickname</td>
<td><input type="text" id="nickname" name="nickname"></td>
</tr>
<tr>
<td>CA Number</td>
<td><input type="text" id="account" name="account"></td>
</tr>
</table>
这是我的实际表格:
<table border="0" cellpadding="0" width="100%" id='providersFormElementsTable'> </table>
这是一种创建 tr
和 td
元素并设定 id
和 labelText
的方法:
function createFormElement(id, labelText) {
// create a new textInputBox button using supplied parameters
var textInputBox = $('<input />').attr({
type: "text", id: id, name: id
});
// create a new textInputBox using supplied parameters
var inputTypeLable = $('<label />').append(textInputBox).append(labelText);
// append the new radio button and label
$('#providersFormElementsTable').append(inputTypeLable).append('<br />');
}
我也有一个值,它将显示为工具提示。请帮我动态创建带有工具提示和的表格。
编辑:
我几乎完成了以下代码:
function createProviderFormFields(id, labelText,tooltip,regex) {
var tr = '<tr>' ;
// create a new textInputBox
var textInputBox = $('<input />').attr({
type: "text",
id: id, name: id,
title: tooltip
});
// create a new Label Text
tr += '<td>' + labelText + '</td>';
tr += '<td>' + textInputBox + '</td>';
tr +='</tr>';
return tr;
}
标签显示正常,但输入框未显示,而且它显示了[object Object]
,应该出现文本框...
当我使用console.log
打印textInputBox
时,我得到以下结果:
[input#nickname, constructor: function, init: function, selector: "", jquery: "1.7.2", size:function...]
问题可能是什么?
感谢@theghostofc
给我指路... :)
Ex: My Home Connection
,那么我只会得到Ex:
,其余的都被跳过了。这就是为什么我没有使用它。:) 感谢您的时间... - Java Questions