所有类(见的jsfiddle例子)jQuery的 - 随着连接复制点击从一个元素到另一个
当“.link_to_rule_them_all”被点击我想所有的“.link_to_rule_them_all跨度”类复制到了#并在每次点击之间清除“#box”。
我的示例代码和的解释是这里http://jsfiddle.net/znCmq/2/
正如你可以看到我有没有关于这个..任何想法js的想法?诶..
所有类(见的jsfiddle例子)jQuery的 - 随着连接复制点击从一个元素到另一个
当“.link_to_rule_them_all”被点击我想所有的“.link_to_rule_them_all跨度”类复制到了#并在每次点击之间清除“#box”。
我的示例代码和的解释是这里http://jsfiddle.net/znCmq/2/
正如你可以看到我有没有关于这个..任何想法js的想法?诶..
$('.link_to_rule_them_all').bind('click', function(e) {
e.preventDefault();
$('#box').attr('class', ($('span', $(this)).attr('class')));
});
使用此:
<a class="link_to_rule_them_all" href="javascript://">
$('.link_to_rule_them_all').click(function() {
$('#box').attr('class',$(this).attr('class'))
})
这是适当的形式使用空HREF而不是散列。
以及href实际上指向某处,所以我想这不会做.. – Joonas 2011-03-28 22:45:30
如果HREF指向某处你会被带到另一个页面,所以你不会看到这一个是怎么回事。 – 2011-03-28 22:56:22
首先,你可以直接添加听者的跨度是这样的:
$('span').click(function(e) {
然后你就可以在类属性添加到DIV
$('#box').append($(e.target).attr('class'));
好吧,让我们试试这个,然后
$('.link_to_rule_them_all').click(function(e) {
//if you wanna attribute the span classes to the #box as classes
var box = $('#box')
box.removeClass();
box.addClass($(this).children('span').attr('class'));
})
如果您想添加跨度类作为文本:
$('.link_to_rule_them_all').click(function(e) {
var box = $('#box');
box.text();
box.append($(this).children('span').attr('class'));
)}
雅,我知道,。点击是只是一个包装的绑定我觉得 – moe 2011-03-28 22:36:04
对不起,我不是肯定的,如果它要紧,但对代码继承人更新..孤单应该是多个环节,一个框元素..问题似乎是它永远不会清除之间的类..它只是继续添加.. http://jsfiddle.net/DfXUU/2/得到我的意思? – Joonas 2011-03-28 22:44:00
我用新的jsfiddle链接更新了解决方案 – moe 2011-03-28 22:52:14