Javascript创建< div>在飞行中 [英] Javascript creating <div> on the fly

查看:44
本文介绍了Javascript创建< div>在飞行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于此的链接

I have a a link that looks similar to this

<a href="/home/category/blog/1" id="blog">Blog</a>

因为你可以链接的ID为'博客',我想要做的是创建一个使用点击的链接中的ID动态获取div,如果点击博客,则标记将是

As you can the link has an ID of 'blog' what I want to do is to create an div on the fly with the ID from the link that was clicked so if the 'blog' is clicked, then the markup would be

<div id="blog">
<!--some content here-->
</div>

如果点击新闻链接就好了,那么我想,

Like wise if for instance the news link is clicked then I would like,

<div id="news">
<!--some content here-->
</div>

?以及我对jQuery的新手。

to be created in the markup if this possible? and how Im pretty new to jQuery.

推荐答案

试试这个:

$("a").click(function(){
    $("#wrapper").append("<div id=" + this.id + "></div>");
});

未经测试,应该工作;)
其中: #wrapper 是父元素,如你所见,可以处理所有 a

Not tested, should work ;) where: #wrapper is parent element, work on all a as you see.

这篇关于Javascript创建&lt; div&gt;在飞行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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