单击按钮更改img src

时间:2017-10-19 10:52:37

标签: javascript jquery html

我已经在这方面工作了一段时间,并且已经在搜索我的修复程序的答案但是找不到它。我正在制作一个二十一点游戏,我一直在使用jQuery来改变图像源。

这是html:

<button id="startgame" type="button" class="btn btn-primary btn-block">Start Game</button>
<div class="col-xs-12">
  <p class="text-center">Player</p>
  <div id='d1pfirstcard' class="col-xs-2">
    <p id="playerside" class="">card one</p>
    <img id="pfirstcard" class="scaled-card" src="Deck/Playing Cards/PNG-cards-1.3/back of card.png">

这是功能:

$('#startgame').click(function() {
  $('#pfirstcard').attr('src', "Deck/Playing Cards/PNG-cards-1.3/2_of_clubs.png");
});

我也尝试过:

$('#startgame').on('click', function() {
  $('#pfirstcard').attr('src', "Deck/Playing Cards/PNG-cards-1.3/2_of_clubs.png");

这是我的标题:                     

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- external CSS file -->
<link rel="stylesheet" type="text/css" href="style.css">

<!-- external js file -->
<script src="application.js"></script>

<title> Black Jack 21</title>

这里有更多我的代码:

 $(document).ready(function(){
let suits = ["Spades", "Clubs", "Hearts", "Diamonds"];
let values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];
let theDeck = new Array();

let playerHandValue = 0;
let dealerHandValue = 0;

 $('#startgame').click(function(){
  $('#pfirstcard').attr('src',"https://placekitten.com/g/500/500");
});

请注意,我下面有更多代码,这就是为什么它没有关闭的原因      });

0 个答案:

没有答案