admin管理员组文章数量:1321427
I have an application here: Application
In the application please do the following:
You will see a green plus button on left hand side, click on it and it will open up a modal window.
In the search bar in the modal window type in the phrase
single
and submit search. A table will be shown below.Add a row from the table by clicking on the "Add" button, it will add the information in the top controls.
Finally click on the "Add Question" button, this will append a table row underneath.
Now the issue I have is that the columns in the <thead>
and the columns in the <tbody>
does not match. What my question is that how can I get these columns to match?
HTML code is below showing the appended rows:
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'>");
var $td = $("<td class='extratd'>");
var $plusrow = $("<td class='plusrow'></td>");
var $qid = $("<td class='qid'></td>").text(qnum);
var $question = $("<td class='question'></td>");
var $noofanswers = $("<div class='noofanswers'>2. Number of Answers:<br/></div>");
var $options = $("<div class='option'>1. Option Type:<br/></div>");
var $answer = $("<div class='answer'>3. Answer:<br/></div>");
var $replies = $("<td class='noofreplies'><div class='wrapper'></div></td>");
var $weight = $("<td class='weight'></td>");
var $image = $("<td class='image'></td>");
var $video = $("<td class='video'></td>");
var $audio = $("<td class='audio'></td>");
...
$tr.append($plusrow);
$tr.append($qid);
$tr.append($question);
$tr.append($td);
$td.append($options);
$td.append($noofanswers);
$td.append($answer);
$tr.append($replies);
$tr.append($weight);
$tr.append($image);
$tr.append($video);
$tr.append($audio);
$tbody.append($tr);
Below is the html table where it contains the table headings columns and where the table rows are appended to:
<table id="qandatbl" align="center">
<thead class="tblhead">
<tr>
<th></th>
<th class="qid">Question No</th>
<th class="question">Question</th>
<th class="optandans">Option and Answer</th>
<th class="noofreplies">Number of Replies</th>
<th class="weight">Number of Marks</th>
<th class="image">Image</th>
<th class="video">Video</th>
<th class="audio">Audio</th>
</tr>
</thead>
<tbody class="tblbody">
</tbody>
</table>
Finally below is the CSS Code:
body{
font-size:85%;
}
#qandatbl{
border:1px black solid;
border-collapse:collapse;
}
#qandatbl td {
vertical-align: middle;
}
#qandatbl th{
border:1px black solid;
border-collapse:collapse;
text-align:center;
}
.tblhead, .tblbody {
display: block;
}
.tblbody{
height: 500px;
overflow: auto;
width:100%;
}
.extratd{
border:1px black solid;
border-collapse:collapse;
}
.qid {
min-width:3%;
max-width:3%;
font-weight:bold;
border:1px black solid;
border-collapse:collapse;
}
.question {
min-width:25%;
max-width:25%;
border:1px black solid;
border-collapse:collapse;
}
.noofanswers{
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.noofreplies{
min-width:3%;
max-width:3%;
border:1px black solid;
border-collapse:collapse;
}
.optandans{
min-width:30%;
max-width:30%;
border:1px black solid;
border-collapse:collapse;
}
.option{
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.weight {
min-width:3%;
max-width:3%;
border:1px black solid;
border-collapse:collapse;
}
.answer {
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.audio{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
}
.video{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
}
.image{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
position:relative;
}
.plusrow{
min-width:2%;
max-width:2%;
border:1px black solid;
border-collapse:collapse;
}
I have included a jsfiddle so you can look at a demo of it and test any ideas you have: /
I have an application here: Application
In the application please do the following:
You will see a green plus button on left hand side, click on it and it will open up a modal window.
In the search bar in the modal window type in the phrase
single
and submit search. A table will be shown below.Add a row from the table by clicking on the "Add" button, it will add the information in the top controls.
Finally click on the "Add Question" button, this will append a table row underneath.
Now the issue I have is that the columns in the <thead>
and the columns in the <tbody>
does not match. What my question is that how can I get these columns to match?
HTML code is below showing the appended rows:
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'>");
var $td = $("<td class='extratd'>");
var $plusrow = $("<td class='plusrow'></td>");
var $qid = $("<td class='qid'></td>").text(qnum);
var $question = $("<td class='question'></td>");
var $noofanswers = $("<div class='noofanswers'>2. Number of Answers:<br/></div>");
var $options = $("<div class='option'>1. Option Type:<br/></div>");
var $answer = $("<div class='answer'>3. Answer:<br/></div>");
var $replies = $("<td class='noofreplies'><div class='wrapper'></div></td>");
var $weight = $("<td class='weight'></td>");
var $image = $("<td class='image'></td>");
var $video = $("<td class='video'></td>");
var $audio = $("<td class='audio'></td>");
...
$tr.append($plusrow);
$tr.append($qid);
$tr.append($question);
$tr.append($td);
$td.append($options);
$td.append($noofanswers);
$td.append($answer);
$tr.append($replies);
$tr.append($weight);
$tr.append($image);
$tr.append($video);
$tr.append($audio);
$tbody.append($tr);
Below is the html table where it contains the table headings columns and where the table rows are appended to:
<table id="qandatbl" align="center">
<thead class="tblhead">
<tr>
<th></th>
<th class="qid">Question No</th>
<th class="question">Question</th>
<th class="optandans">Option and Answer</th>
<th class="noofreplies">Number of Replies</th>
<th class="weight">Number of Marks</th>
<th class="image">Image</th>
<th class="video">Video</th>
<th class="audio">Audio</th>
</tr>
</thead>
<tbody class="tblbody">
</tbody>
</table>
Finally below is the CSS Code:
body{
font-size:85%;
}
#qandatbl{
border:1px black solid;
border-collapse:collapse;
}
#qandatbl td {
vertical-align: middle;
}
#qandatbl th{
border:1px black solid;
border-collapse:collapse;
text-align:center;
}
.tblhead, .tblbody {
display: block;
}
.tblbody{
height: 500px;
overflow: auto;
width:100%;
}
.extratd{
border:1px black solid;
border-collapse:collapse;
}
.qid {
min-width:3%;
max-width:3%;
font-weight:bold;
border:1px black solid;
border-collapse:collapse;
}
.question {
min-width:25%;
max-width:25%;
border:1px black solid;
border-collapse:collapse;
}
.noofanswers{
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.noofreplies{
min-width:3%;
max-width:3%;
border:1px black solid;
border-collapse:collapse;
}
.optandans{
min-width:30%;
max-width:30%;
border:1px black solid;
border-collapse:collapse;
}
.option{
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.weight {
min-width:3%;
max-width:3%;
border:1px black solid;
border-collapse:collapse;
}
.answer {
min-width:100%;
max-width:100%;
padding-top:5%;
padding-bottom:5%;
}
.audio{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
}
.video{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
}
.image{
min-width:11%;
max-width:11%;
border:1px black solid;
border-collapse:collapse;
position:relative;
}
.plusrow{
min-width:2%;
max-width:2%;
border:1px black solid;
border-collapse:collapse;
}
I have included a jsfiddle so you can look at a demo of it and test any ideas you have: http://jsfiddle/heA2b/1/
Share Improve this question edited Dec 19, 2012 at 23:02 user1881090 asked Dec 19, 2012 at 22:54 user1881090user1881090 7415 gold badges17 silver badges35 bronze badges 2- green button doesnt work – user1721135 Commented Dec 19, 2012 at 23:02
- Just get a php error and button does nothing – Dave Sexton Commented Dec 19, 2012 at 23:17
1 Answer
Reset to default 6The first answer (user1721135) is incorrect, it's because you've assigned the thead and tbody a display of "block". Remove that and your problem will disappear.
He is right that you don't have to assign a mix and a max-width if they are the same, but that's not what is causing your issue.
Edit to add working example: http://codepen.io/joe/pen/gqzbf
本文标签: javascriptColumns not matching between thead and tbodyStack Overflow
版权声明:本文标题:javascript - Columns not matching between thead and tbody - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742102480a2420865.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论