javascript - Using Document Ready on Click Event -


I'm still new to javascript.

I have an app that has two buttons on the page. There is a cpu_vs_player button that shows a game and the other is a player who displays a different game. The problem is that all the code is located in an application.js file. There is no need to load player_vs_player on $ (document) .ready (function () {}); If I had to play cpu_vs_player

How can I do but if I had chosen that game then bring them to load? (I'm just using a route with hidden / visible information on the basis of clicks).

Documents. There is nothing after the page page and the event needs to be documented with listeners. Clearly this is the only way to skin this cat.

You can either do the jQuery method where you split JavaScript and HTML:

  & lt; Button id = "button1" & gt; Cpu_vs_player & lt; / Button & gt; & Lt; Button id = "button2" & gt; Player_vs_player & lt; / Button & gt; For javascript:  

Assume that the function for each of your gameplay is:

  function cpu_vs_player () {/ / Start the game} function player_vs_player () {// another player is required}   

Add event paths to jQuery:

  $ (document ) .ready (function (($ ("$ button1"). (Function () {cpu_vs_player ();}); $ ("# button1") Click (function () {player_vs_player ();}) ;});   

OR You can use the method @ Texton shows you, However, you can make it more direct all this work.

  button onclick = "javascript: cpu_vs_player ();" & gt; cpu_vs_player & lt; / button & gt; ; & Lt; button onclick = "javascript: player_vs_player ();" & gt; player_sw_player & lt; / button & gt;    warning ("start cpu_vs_player");} Player_vs_player: Function () {Warning ("player player_vs_player start");}}   

In your HTML:

  & lt; Button onclick = "javascript: main.cpu_vs_player ();" & Gt; Cpu_vs_player & lt; / Button & gt; & Lt; Button onclick = "javascript: main.player_vs_player ();" & Gt; Player_sw_player & lt; / Button & gt;   

And yes, there is more ...; -)

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -