2013-10-09 40 views
0

如何将一个元素的样式放入另一个元素中?我的目标是摆脱包装和.ui可调整大小的处理程序,只留下img,但用替换的样式形成包装。 这可能吗?如何将样式从一个元素传输到另一个元素?

<div class="ui-wrapper ui-draggable" style="overflow: hidden; position: absolute; width: 492px; height: 411px; top: 105px; left: 409px; margin: 0px;"> 

    <img id="link1" style="position: static; margin: 0px; resize: none; zoom: 1; display: block; height: 411px; width: 492px;" src="http://i.imgur.com/gKY7j0l.jpg" class="ui-resizable"> 

    <div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"> 
    </div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"> 
    </div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"> 
    </div> 
</div> 

,以便在这个例子中,结果会是从包装样式的IMG:

<img id="link1" style="overflow: hidden; position: absolute; width: 492px; height: 411px; top: 105px; left: 409px; margin: 0px;" src="http://i.imgur.com/gKY7j0l.jpg" class="ui-resizable"> 
+0

您是否尝试过的东西为自己,没有? – nuke

回答

0

我是一个新手,JQuery的仅为经验几个月。 但是,我认为这应该工作。

var hold = $('div.ui-wrapper.ui-draggable').attr('style'); 
$('#link1').attr('style',hold); 

然后,您可以删除包装或做任何你必须做的事情。 要从包装中解包http://api.jquery.com/unwrap/应该是有用的。

0

你应该把风格放入课堂。 Forexample:

<div class="ui-wrapper ui-draggable" style="overflow: hidden; position: absolute; width: 492px; height: 411px; top: 105px; left: 409px; margin: 0px;"> 

<img id="link1" style="overflow: hidden; position: absolute; width: 492px; height: 411px; top: 105px; left: 409px; margin: 0px;" src="http://i.imgur.com/gKY7j0l.jpg" class="ui-resizable"> 

<div class="ui-wrapper ui-draggable WRAP"> 
<img id="link1" class="ui-resizable WRAPIMG"> 

那么你可以使用某物像那:

$('#link1').unwrap().removeClass('WRAPIMG').addClass('WRAP'); 
相关问题