jQuery< / body>标签可能吗? [英] jQuery </body> tag possible?

查看:93
本文介绍了jQuery< / body>标签可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何创建一个元素后关闭正文标签


做了搜索,找不到这个。

是否有可能让jQuery关闭 < / body> 标记,然后在上面添加一些JS代码?
IE:find:

  $(< / body>)

$ b

然后在这个标记的上面添加一些JS脚本?

解决方案你不需要选择'closing'标签,只需选择正文并追加你想要的:

 <$ c 。$ C> $( '主体')附加( '< H1> foobar的< / H1>'); 

更新
<正如@meagar提到的那样,使用jQuery你不会选择'闭'标签,而是整个'元素',例如身体,或一个'段'(p)作为一个整体



试图使其更清楚,这个代码:

 < body> 
< p>我的段落< / p>
< script>
$(body).append('< p>新段落< / p>');
< / script>
< / body>

会产生这样的结果:

 <身体GT; 
< p>我的段落< / p>
< script>
$(body).append('< p>新段落< / p>');
< / script>
< p>新段落< / p>
< / body>

新的段落附加在主体的结尾处


Possible Duplicate:
How do I create an element after the closing body tag

Did a search, could not find this.

Is it possible to jQuery the closing </body> tag and then add some JS code just above? IE: find:

$("</body>") 

Then add some JS script just above this tag?

解决方案

You don't need to select the 'closing' tag, just select the body and append what you want:

$('body').append('<h1>foobar</h1>');

update

As @meagar mentioned correctly, with jQuery you don't select a 'closing' tag, but the whole 'element', e.g. the body, or a 'paragraph' (p) as a whole

Trying to make it more clear, this code:

<body>
    <p>my paragraph</p>
    <script>
       $(body).append('<p>new paragraph</p>');
    </script>
</body>

Will produce this result:

<body>
    <p>my paragraph</p>
    <script>
       $(body).append('<p>new paragraph</p>');
    </script>
    <p>new paragraph</p>
</body>

The new paragraph is appended at the end of the body

这篇关于jQuery&lt; / body&gt;标签可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆