2009-12-18 81 views
1

我還是這方面的新手,很少有問題。如何在此JQuery中添加html屬性

我有JQuery的從這個站點: http://goskylar.com/wp-content/demos/jquery.hyphenate/

這是解決我就斷字的問題。 但是,當我把一些html標記,如<強>或<u>結果顯示沒有效果。 我的問題是:
我應該在哪裏以及如何爲css attribut添加函數,以便它可以顯示< strong>或< u>結果?

--edited--

<script> 
(function($){$.fn.hyphenate=function(options) { 
    settings=$.extend({oWidth:this.width()},options); 

return this.each(function(){ 
    $(this).css({ 
    'width':settings.oWidth, 
    'display':'block' 
    }); 
    var str=''; 
    $.each($(this).text().split(' '),function(i,chunk){str+=splitChunk(chunk)+' ';}); 
    $(this).html(str);  
}); 

function splitChunk(str){ 
    if($('<span></span>').text(str).hide().appendTo(document.body).width() > settings.oWidth) 
    {var s=''; var i=0; 
    while(i < str.length) 
    { 
     s+=(str.slice(i,++i)+'&shy;'); 
    } 
    return s; 
    } 
    else 
    return str; 
    } 
    }; 

})(jQuery); 
</script> 

<html> 
<head> 
<title>Hyphenation</title> 
</head> 
<body> 

<script> 
jQuery(document).ready(function(){ 
    $('#d4').hyphenate({oWidth:158}); 
}); 
</script> 

<div id="d4">this will start with <u>spaces and this firstthisi<strong>sareallylongsentence</strong>withlotsots</u>andlotsofwords</div> 
</body> 
</html> 

回答

1

關於#2,您要添加/更改元素的屬性? jQuery doc and example

更多jQuery Attributes

關於#1,你能否詳細說明嗎?你在說什麼查詢?

+0

對不起,這不是查詢,而是實際上jquery.hypheante.js本身。 – Febri 2009-12-18 06:43:27