2012-04-17 5 views
1

を追加私はDOMに新しいCSSルールを追加することができるように、Rule PluginjQueryのルールのプラグイン - 私のプロジェクトのために新しいルール

その偉大なように見えるのjQueryを使用する必要があります。

しかし、どうすれば新しいルールを作成し、それをdomに追加できますか?

These are the methods, the plugin adds to the different namespaces. 

jQuery.fn 
- sheet: returns the stylesheets from the matched styles and links. 
- cssRules: return all the rules from all the given sheets. 
- ownerNode: returns the nodes that belong to the given sheet (opposite to sheets). 
- cssText: returns the text of the first matched style/link. 

jQuery.rule 
- constructor($.rule): 
    - 1st argument: nothing, a rule filter, rule literal, css rule or array of rules. 
    - 2nd argument: nothing, node filter for link/style, nodes link/style. 
- sheets: returns the sheets that match the selector or all of them if none. 
- clean: converts a rule literal, to array of rules. 
- parent: returns the parent of a rule, neccesary for IE. 
- outerText: return the selector with the rules of the given rule. 
- text: gets/sets the cssText of the rule. 

jQuery.rule.fn 
- append: will add one or more styles in the form of "attr:value; attr:value" to the matched rules. 
- css : sets a value to all matched rules. 
- outerText: return $.rule.outerText of the first rule. 
- text: sets the cssText of the rules, or gets the cssText from the first one. 
- appendTo: appends the matched rules to the specified stylesheet(1), can be a selector, dom element, sheet. 

All these methods (from jQuery.rule.fn) are equal (or very similar) to those in jQuery.fn, but for CSS Rules. 
    add, andSelf, animate, appendTo, attr, css, dequeue, 
    each, end, eq, fadeIn, fadeOut, fadeTo, filter, get, 
    hide, index, is, map, not, pushStack, queue, remove, 
    setArray, show, size, slice, stop, toggle. 

Some calls to show and hide behave unexpectedly sometimes. Some styles and animations might fail. 

が私を助けてください:

ドキュメントがいることを述べています。

ありがとうございます。

注:私はあなたがjQueryのについて何かを知っていればそれを行うのは非常に簡単かもしれ確信しているが、あなたが初心者であれば、それはそれは難しいでしょう、私はこのことについていくつかの情報を得るためにGoogleを試してみましたが、何かを見つける傾けます。私は質問What you tried ?に慣れている、ここで私は知らない!これはスタートです。ありがとうございました !

+1

例はここにある:http://flesler.webs.com/jQuery.Rule/ –

+0

@AlanKuras私は、以前のことを確認しますが、追加する方法を見つけることができませんでした新しいルール、 – Red

答えて

2

Basicの例:この例では

$.rule('#some_id','style').append('font-size:17px'); 

'some_id' という名前のCSSのIDに新しいスタイルを追加しますそのルール。フォントサイズを17pxに設定する新しいCSSルールを追加します。

だから、基本的にあなたがhttp://flesler.webs.com/jQuery.Rule/API.txt

ここで説明するパラメータを指定して「$ .rule」キーワードを使用して新しいルールを作成しているあなたは、ここでより多くの例を得ることができます:もちろんhttp://flesler.webs.com/jQuery.Rule/

を最初にあなたはjQueryとそのプラグインを含める必要が例えばあなたのための文書です。

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.rule.js"></script> 
+0

ありがとう... thats it !! – Red

+0

あなたの歓迎: –

+0

これは動作しません。これは#some_idのCSSルールが既に存在する場合にのみ有効です。 –

1

jQueryルールを使用しないでください。そのドキュメントは非常に悪いです。 JSSははるかに良いです:https://github.com/Box9/jss。あなたはJSSでやりたい方法:

jss('#some_id', { 
    fontSize: '17px' 
}); 
+1

トロールすることはしませんが、JSSのドキュメントははるかに薄く、GitHubで報告されている未解決の問題のいくつかについて、プラグインは自動的に失敗します。 jQuery.ruleはより多くの機能を提供し、GitHubには何の問題も報告されていません。 – Barney

関連する問題