Changing variable by html button

前端 未结 8 1213
野的像风
野的像风 2021-01-18 00:23

I\'m learning javascript and I decided to create simple Rock, Paper, Scissors game. I want to make it controllable by buttons. So I made this in html:



        
8条回答
  •  有刺的猬
    2021-01-18 01:28

    Maybe try this.. cleaner markup.. uses jQuery



    $(document).ready(function() { var user = "none"; $(".user").click(function() { user = $(this).attr("data-name"); }); $("#test").click(function() { alert(user); }); });

    http://jsfiddle.net/rQDbe/

提交回复
热议问题