Javascript 如何使用Jquery在DIV标记内创建表?
我已经使用创建了一个数据表Javascript 如何使用Jquery在DIV标记内创建表?,javascript,jquery,html,html-table,Javascript,Jquery,Html,Html Table,我已经使用创建了一个数据表 <script> var table = '<table border="0" id="tblTestCases">'; table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of text boxes = " + $searchObject.find('[type=text]').length + "</td></tr&g
<script>
var table = '<table border="0" id="tblTestCases">';
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of text boxes = " + $searchObject.find('[type=text]').length + "</td></tr>";
$searchObject.find('[type=text]').each(function () {
table+="<tr bgcolor='#ccccff'><td>Name of textbox = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if cursor is displayed/blinking after mouse click <br /> 2)Check if a text can be entered inside</td></tr>";
});
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of Submit Buttons = " + $searchObject.find('[type=submit]').length + "</td></tr>";
$searchObject.find('[type=submit]').each(function () {
table+="<tr bgcolor='#6666ff'><td>Name of Submit button = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if the button is clickable or not <br /> 2) Check if the submission result is displayed after mouse click";
});
</script>
var表=“”;
table+=“文本框的数量=“+$searchObject.find”(“[type=text]”)。长度+”;
$searchObject.find('[type=text]')。每个(函数(){
table++=“textbox的名称=“++$(this).attr(“Name”)+”ID=“++$(this).attr(“ID”)+”测试用例:
1)检查鼠标单击后是否显示光标/闪烁
2)检查是否可以在其中输入文本”;
});
表+=“提交按钮数=“+$searchObject.find”(“[type=Submit]”)。长度+”;
$searchObject.find('[type=submit]')。每个(函数(){
table++=“提交按钮的名称=“++$(this).attr(“Name”)+”ID=“++$(this).attr(“ID”)+”测试用例:
1)检查按钮是否可单击
2)检查鼠标单击后是否显示提交结果”;
});
我想把桌子放在一个DIV标签里。但是脚本是在主体内部创建表,而不是我想要的位置。有没有办法把同一张桌子放在沙发里
提前谢谢。
表中有很多条目。为了演示,我只添加了2个
<script>
var table = '<table border="0" id="tblTestCases">';
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of text boxes = " + $searchObject.find('[type=text]').length + "</td></tr>";
$searchObject.find('[type=text]').each(function () {
table+="<tr bgcolor='#ccccff'><td>Name of textbox = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if cursor is displayed/blinking after mouse click <br /> 2)Check if a text can be entered inside</td></tr>";
});
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of Submit Buttons = " + $searchObject.find('[type=submit]').length + "</td></tr>";
$searchObject.find('[type=submit]').each(function () {
table+="<tr bgcolor='#6666ff'><td>Name of Submit button = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if the button is clickable or not <br /> 2) Check if the submission result is displayed after mouse click";
});
</script>
现在做:
$("#testing").html(table);
在html中使用以下代码段作为容器:
并像这样更新脚本
<script>
var table = '<table border="0" id="tblTestCases">';
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of text boxes = " + $searchObject.find('[type=text]').length + "</td></tr>";
$searchObject.find('[type=text]').each(function () {
table+="<tr bgcolor='#ccccff'><td>Name of textbox = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if cursor is displayed/blinking after mouse click <br /> 2)Check if a text can be entered inside</td></tr>";
});
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of Submit Buttons = " + $searchObject.find('[type=submit]').length + "</td></tr>";
$searchObject.find('[type=submit]').each(function () {
table+="<tr bgcolor='#6666ff'><td>Name of Submit button = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if the button is clickable or not <br /> 2) Check if the submission result is displayed after mouse click";
});
$("#container").html(table);
</script>
var表=“”;
table+=“文本框的数量=“+$searchObject.find”(“[type=text]”)。长度+”;
$searchObject.find('[type=text]')。每个(函数(){
table++=“textbox的名称=“++$(this).attr(“Name”)+”ID=“++$(this).attr(“ID”)+”测试用例:
1)检查鼠标单击后是否显示光标/闪烁
2)检查是否可以在其中输入文本”;
});
表+=“提交按钮数=“+$searchObject.find”(“[type=Submit]”)。长度+”;
$searchObject.find('[type=submit]')。每个(函数(){
table++=“提交按钮的名称=“++$(this).attr(“Name”)+”ID=“++$(this).attr(“ID”)+”测试用例:
1)检查按钮是否可单击
2)检查鼠标单击后是否显示提交结果”;
});
$(“#容器”).html(表格);
将其添加到正文的当前代码在哪里?将其添加到div的代码将非常相似。可能重复@MidhunT的代码请向上投票并将其标记为正确答案。
<script>
var table = '<table border="0" id="tblTestCases">';
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of text boxes = " + $searchObject.find('[type=text]').length + "</td></tr>";
$searchObject.find('[type=text]').each(function () {
table+="<tr bgcolor='#ccccff'><td>Name of textbox = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if cursor is displayed/blinking after mouse click <br /> 2)Check if a text can be entered inside</td></tr>";
});
table+="<tr bgcolor='#e6e6e6'><td colspan='3'>Number of Submit Buttons = " + $searchObject.find('[type=submit]').length + "</td></tr>";
$searchObject.find('[type=submit]').each(function () {
table+="<tr bgcolor='#6666ff'><td>Name of Submit button = " + $(this).attr("name") + "</td><td> ID =" + $(this).attr("id") + "</td><td> Test cases : <br /> 1) Check if the button is clickable or not <br /> 2) Check if the submission result is displayed after mouse click";
});
$("#container").html(table);
</script>