2013-10-09 59 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'); 
相關問題