RJS参考之JavaScriptGenerator

RJS模板中的page即JavaScriptGenerator类的对象,它有如下方法:
<<(javascript)

Writes raw JavaScript to the page.

[](id)

Returns a JavaScriptElementProxy for the DOM element with the specified id. Methods can be called on the returned element. Multiple method calls can also be chained together.

assign(variable, value)

Assigns a value to the JavaScript variable specified. Ruby objects are automatically converted to JavaScript objects by calling the object's to_json method if it has one, or inspect if it doesn't.

alert(message)

Displays a JavaScript alert dialog box with the provided message.

call(function, arg, ...)

Calls a JavaScript function and passes in zero or more arguments.

delay(seconds = 1)

Executes the code within the block after delaying for the specified number of seconds.

draggable(id, options = {})

Makes the DOM element specified by the id draggable.

drop_receiving( id, options = {})

Makes the DOM element specified by the id receive dropped draggable elements. Draggable elements are created using the RJS draggable method or by using draggable_element() Scriptaculous helper.

hide(id, ...)

Hides one or more DOM elements. Specify the elements to hide by their DOM ids.

insert_html(position, id, *options_for_render)

Inserts the HTML into the specified position in relation to the element.
The available positions are:
:before
The content is inserted into the page before the element.
:after
The content is inserted into the page after the element.
:top
The content is inserted into the element before the element's existing content.
:bottom
The content is inserted into the element after the element's existing content.

redirect_to(location)

Redirect the browser to the location specified. redirect_to() passes the location to url_for(), so any of the arguments you normally use with url_for() can also be used with redirect_to().

remove(id, ...)

Removes one or more DOM elements from the page.

replace(id, *options_for_render)

Replaces the entire element specified or outerHTML. replace is useful with partial templates so that the entire partial, which includes a container element, can be rendered and used to replace content during an RJS call. An example is an unordered list. A partial containing a <li> tag can be rendered instead of having to replace the innerHTML of the <li> . Replacing just the innerHTML would require the <li> tag to be moved out of the partial.

replace_html(id, *options_for_render)

Replaces the content or innerHTML of the DOM element with the id with either a String or the output of a rendered partial template.

select(pattern)

Selects DOM elements using CSS-based selectors. Returns a JavaScriptElementCollectionProxy that can then receive proxied enumerable methods. See the JavaScriptCollectionProxy methods in the next section.

sortable(id, options = {})

Makes the element with the DOM ID id sortable using drag and drop. The options are the same as the options for ScriptaculousHelper#sortable_element().

show(id, ...)

Makes one or more hidden DOM elements visible. As with hide(), the elements are specified by their DOM ids.

toggle(id, ...)

Toggles the visibility of one or more DOM objects.

visual_effect(name, id = nil, options = {})

Creates a new Scriptaculous visual effect to the element with the DOM id. See the following section on visual effects for a list of the visual effects shipping with Rails 1.1.

你可能感兴趣的:(JavaScript,json,css,Ruby,Rails)