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 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: Assume that the function for each of your gameplay is: Add event paths to jQuery: OR You can use the method @ Texton shows you, However, you can make it more direct all this work. In your HTML: And yes, there is more ...; -) $ (document) .ready (function () {}); If I had to play cpu_vs_player
& lt; Button id = "button1" & gt; Cpu_vs_player & lt; / Button & gt; & Lt; Button id = "button2" & gt; Player_vs_player & lt; / Button & gt; For javascript:
function cpu_vs_player () {/ / Start the game} function player_vs_player () {// another player is required}
$ (document ) .ready (function (($ ("$ button1"). (Function () {cpu_vs_player ();}); $ ("# button1") Click (function () {player_vs_player ();}) ;});
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");}}
& 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;
Comments
Post a Comment