jQuery 规则插件 - 添加新规则

标签 jquery css jquery-plugins

对于我的元素,我需要使用 jQuery Rule Plugin

它看起来很棒,这样我就可以将新的 css 规则附加到 dom 中。

但是我如何创建一个新规则并将其附加到 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 获取有关此的一些信息,但找不到任何内容。我很熟悉这个问题你尝试了什么?,这里我不知道!请这是一个开始。谢谢!

最佳答案

基本示例:

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

在此示例中,它的规则将向名为“some_id”的 css id 添加新样式。它将附加新的 css 规则,将 font-size 设置为 17px;

所以基本上您正在使用“$.rule”关键字和此处描述的参数创建新规则 http://flesler.webs.com/jQuery.Rule/API.txt

您可以在此处获取更多示例:http://flesler.webs.com/jQuery.Rule/

当然首先你需要在你的文档中包含 jquery 和这个插件,例如。像这样:

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

关于jQuery 规则插件 - 添加新规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189286/

相关文章:

javascript - jQuery javascript 检查页面上是否存在某些 html 的方法

javascript - 如何从 HtmlTableCellElement 获取文本

css - 图像差异 IE7 到 IE8/IE9/FF4

php - $_SESSION 的问题是 jQuery

javascript - 未捕获的类型错误 : Object #<Object> has no method 'tree'

jquery - 无法控制 Twitter Bootstrap 中菜单元素的颜色

javascript - 如何在不实际禁用按钮的情况下暂时禁用按钮上的单击事件?

html - 如何将 Bootstrap 底部导航栏移动到所需位置?

javascript - 我该如何修复 JS 以使文本不会被删除并继续累积?

jquery-mobile - Blueimp Jquery 文件上传插件未上传移动设备上的所有文件(在桌面上运行良好)