1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | AddBook( { id: 1, name: 'Code Generation in Action', first: 'Jack', last: 'Herrington', publisher: 'Manning' } ); AddBook( { id: 2, name: 'PHP Hacks', first: 'Jack', last: 'Herrington', publisher: 'O\'Reilly' } ); ... |
1 2 3 4 5 6 | ... <script> var g_books = []; function AddBook( book ) { g_books.push( book ); } </script> ... |
1 2 3 4 5 6 7 8 9 10 11 12 | ... <xsl:template match="/"> <xsl:for-each select="books/book"> AddBook( { id: <xsl:value-of select="@id" />, name: '<xsl:value-of select="js:escape(title)" />', first: '<xsl:value-of select="js:escape(author/first)" />', last: '<xsl:value-of select="js:escape(author/last)" />', publisher: '<xsl:value-of select="js:escape( publisher )" />' } );</xsl:for-each> </xsl:template> ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | g_books.push( new Book( { id: 1, name: 'Code Generation in Action', first: 'Jack', last: 'Herrington', publisher: 'Manning' } ) ); g_books.push( new Book( { id: 2, name: 'PHP Hacks', first: 'Jack', last: 'Herrington', publisher: 'O\'Reilly' } ) ); |
1 2 3 4 5 6 7 8 9 10 | <xsl:template match="/"> <xsl:for-each select="books/book"> g_books.push( new Book( { id: <xsl:value-of select="@id" />, name: '<xsl:value-of select="js:escape(title)" />', first: '<xsl:value-of select="js:escape(author/first)" />', last: '<xsl:value-of select="js:escape(author/last)" />', publisher: '<xsl:value-of select="js:escape( publisher )" />' } ) );</xsl:for-each> </xsl:template> |
1 2 3 4 5 6 7 8 9 | ... <script> var g_books = []; function Book( data ) { for( var d in data ) { this[d] = data[d]; } } </script> ... |
1 2 3 4 5 6 7 8 9 10 11 12 | var b1 = new Book(); b1.setId ( 1 ); b1.setTitle ( 'Code Generation in Action' ); b1.setFirst ( 'Jack' ); b1.setLast ( 'Herrington' ); b1.setPublisher ( 'Manning' ); g_books.push( b1 ); var b2 = new Book(); b2.setId ( 2 ); b2.setTitle ( 'PHP Hacks' ); ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ... <xsl:function name="js:createbook"> <xsl:param name="book" /> <xsl:variable name="b" select="concat( 'b', $book/@id )" /> var <xsl:value-of select="$b" /> = new Book(); <xsl:value-of select="concat( $b, '.setId' )" /> ( <xsl:value-of select="$book/@id" /> ); <xsl:value-of select="concat( $b, '.setTitle' )" /> ( '<xsl:value-of select="js:escape( $book/title )" />' ); <xsl:value-of select="concat( $b, '.setFirst' )" /> ( '<xsl:value-of select="js:escape( $book/author/first )" />' ); <xsl:value-of select="concat( $b, '.setLast' )" /> ( '<xsl:value-of select="js:escape( $book/author/last )" />' ); <xsl:value-of select="concat( $b, '.setPublisher' )" /> ( '<xsl:value-of select="js:escape( $book/publisher )" />' ); </xsl:function> <xsl:template match="/"> <xsl:for-each select="books/book"> <xsl:value-of select="js:createbook(.)" /> g_books.push( b<xsl:value-of select="@id" /> ); </xsl:for-each> </xsl:template> ... |
1 2 3 4 5 6 7 8 9 10 11 | ... <script> var g_books = []; function Book() { } Book.prototype.setId = function( val ) { this.id = val; } Book.prototype.setTitle = function( val ) { this.name = val; } Book.prototype.setFirst = function( val ) { this.first = val; } Book.prototype.setLast = function( val ) { this.last = val; } Book.prototype.setPublisher = function( val ) { this.publisher = val; } </script> ... |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |