简体   繁体   English

完全从源中删除标记

[英]Completly remove a tag from the source

I would like to remove a tag with the class of '.de'. 我想删除类为'.de'的标记。

$('.de').remove(); will remove it from the page but when I check the source code, then I still see the tag. 将它从页面中删除但是当我检查源代码时,我仍然看到标记。

The problem that I have is, the following tag needs to be removed from the form, otherwise it will get sent and that's not what I want. 我遇到的问题是,需要从表单中删除以下标记,否则它将被发送,这不是我想要的。

<input class="input_field_left de" name="friend_vorname[]" type="text" placeholder="Vorname">

Or maybe there is another way to not let this field get sent?! 或者也许有另一种方法不让这个字段被发送?!

This is just how "view source" works in browsers. 这就是“查看源”在浏览器中的工作方式。 It shows you what came from the server (and usually re-queries it from the server [which may read it from cache]), not what is currently in the page. 它向您显示来自服务器的内容(通常从服务器重新查询它[可能从缓存中读取]), 而不是页面中当前的内容。

To see what's currently in the page, you need to use the "Elements" or "DOM" tab in your browser's dev tools (usually opened via F12 or Ctrl+Shift+I). 要查看页面中当前的内容,您需要在浏览器的开发工具中使用“元素”或“DOM”选项卡(通常通过F12或Ctrl + Shift + I打开)。 You can usually open it and move to a specific element by right-clicking that element on your page and choosing "Inspect element", so if you do that with your form after your $('.de').remove(); 您通常可以通过右键单击页面上的元素并选择“Inspect element”来打开它并移动到特定元素,因此如果您在$('.de').remove();之后使用表单执行此操作$('.de').remove(); is run, you'll see the form without the .de elements in it. 运行后,您将看到没有.de元素的表单。

The problem that I have is, the following tag needs to be removed from the form, otherwise it will get sent and that's not what I want. 我遇到的问题是,需要从表单中删除以下标记,否则它将被发送,这不是我想要的。

No, it won't. 不,它不会。 Your $('.de').remove(); 你的$('.de').remove(); will remove any matching elements from the page, and they will not be submitted with the form if the form is then submitted. 将从页面中删除任何匹配的元素,如果随后提交表单,它们将不会随表单一起提交。

如果你想尝试用jQuery添加标签,你不能用j Query从源代码中删除标签。(动态创建的标签或元素只能用jQuery动态删除。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM