html通过jquery追加问题

发布于 2024-11-14 14:40:28 字数 2448 浏览 3 评论 0原文

您好,我正在通过 jquery 将列附加到行。 我有一行看起来像这样

<form action="certifications.php?action=addnew_save" method="post">
<tr id="add_new_<?php echo($v_id);?>" valign="top" bgcolor="#EEEEEE"></tr>
</form>

现在我正在做什么,我将一些 附加到这一行。我的 javascript 函数如下所示

var sr=document.getElementById('hidden_'+vid).value;
var append='';
    append+='<td width="40" align="center">'+sr+'</td>';
    append+='<input type="hidden" value="'+vid+'">';
    append+='<td width="200" align="center"><input type="text" name="short_name" size="25" autocomplete="off" value="" /></td>';
    append+='<td width="200" align="center"><input type="text" name="full_name" size="25" autocomplete="off" value="" /></td>';
    append+='<td width="80" align="center"></td>';
    append+='<td width="80" align="center"><input type="checkbox" name="feature" /></td>';
    append+='<td width="80" align="center"><input type="text" name="order" size="2" value="" /></td>';
    append+='<td width="80" align="center"><input type="checkbox" name="hidden" /></td>';
    append+='<td width="80" align="center"></td>';
    append+='<td width="50" class="style3" align="center"></td>';
    append+='<td width="50" class="style3" align="center"><INPUT TYPE="submit"  VALUE="Submit" NAME="Submit"></td>';
    append+='<td width="50" class="style3" align="center"><a href="certifications.php?action=delete&id="onclick="if(confirm(\'Are you sure you want to Delete it ?\')){return true;}else{return false;}" >Delete</a></td>';
    append+='<td width="80" align="center"></td>';
    jQuery('#add_new_'+vid).append(append);

列已附加,但问题出在 form 标记上。从我的代码中,我希望附加 html 后应该看起来像这样

<form action="certifications.php?action=addnew_save" method="post">
<tr id="add_new_<?php echo($v_id);?>" valign="top" bgcolor="#EEEEEE">
 <td widht="40">Value</td>
 Other tds
  .
  .
  .
  .
</tr>
</form>

,但是我得到了上面的表单标签 ,它看起来像这样

   <form action="certifications.php?action=addnew_save" method="post">
   </form>
    <tr>
     my <td>
    </tr>

附加时有什么问题?为什么表单标签总是在上面

Hi I am appending columns to a row though jquery.
I have a row which looks like this

<form action="certifications.php?action=addnew_save" method="post">
<tr id="add_new_<?php echo($v_id);?>" valign="top" bgcolor="#EEEEEE"></tr>
</form>

Now What I am doing, I am appending some <td> to this row. My javascript function looks like this

var sr=document.getElementById('hidden_'+vid).value;
var append='';
    append+='<td width="40" align="center">'+sr+'</td>';
    append+='<input type="hidden" value="'+vid+'">';
    append+='<td width="200" align="center"><input type="text" name="short_name" size="25" autocomplete="off" value="" /></td>';
    append+='<td width="200" align="center"><input type="text" name="full_name" size="25" autocomplete="off" value="" /></td>';
    append+='<td width="80" align="center"></td>';
    append+='<td width="80" align="center"><input type="checkbox" name="feature" /></td>';
    append+='<td width="80" align="center"><input type="text" name="order" size="2" value="" /></td>';
    append+='<td width="80" align="center"><input type="checkbox" name="hidden" /></td>';
    append+='<td width="80" align="center"></td>';
    append+='<td width="50" class="style3" align="center"></td>';
    append+='<td width="50" class="style3" align="center"><INPUT TYPE="submit"  VALUE="Submit" NAME="Submit"></td>';
    append+='<td width="50" class="style3" align="center"><a href="certifications.php?action=delete&id="onclick="if(confirm(\'Are you sure you want to Delete it ?\')){return true;}else{return false;}" >Delete</a></td>';
    append+='<td width="80" align="center"></td>';
    jQuery('#add_new_'+vid).append(append);

The columns are appended but the problem is of form tag. From my code I want the after appending the html should look like this

<form action="certifications.php?action=addnew_save" method="post">
<tr id="add_new_<?php echo($v_id);?>" valign="top" bgcolor="#EEEEEE">
 <td widht="40">Value</td>
 Other tds
  .
  .
  .
  .
</tr>
</form>

But I am getting the form tag above <tr> and it looks like this

   <form action="certifications.php?action=addnew_save" method="post">
   </form>
    <tr>
     my <td>
    </tr>

What is the problem in appending? Why form tag is always above

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2024-11-21 14:40:28

更改

jQuery('#add_new_'+vid).append(append);

jQuery('#add_new_'+vid).html(append);

您不想在该元素之后添加代码,但您试图将其插入到 tr 中。

更新:从技术上讲,您不应该用

包装 ,它的 HTML 无效。 tr 必须是表或 tbody 的子元素,并且 tr 元素必须将 td 作为子元素。您要么需要在每个 td 中使用一个表单,要么需要您的表单包裹整个表格。

Change

jQuery('#add_new_'+vid).append(append);

to

jQuery('#add_new_'+vid).html(append);

You don't want to add your code after the element, but you are trying to insert it into the tr.

UPDATE: Technically you should not be wrapping a <tr> with a <form>, its invalid HTML. A tr must be a child of a table, or tbody, and tr elements must have td as children. You'll either need a form in each td, or you'll need your form to wrap the entire table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文