Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

android button - How can i change imagebutton background on onclick


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

var clicked = 0
$("#button").click(function() {
  if (clicked == 0) {
    $(this).css("background", "url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQm19_RGu6ZbKhn_uryzGqZLIldxuLIYX-m6A&usqp=CAU) no-repeat");
    clicked = 1;
  } else {
    $(this).css("background", "url(https://lesspestcontrol.com.au/wp-content/uploads/green-tick.png) no-repeat");
    clicked = 0;
  }
})
.button {
  width: 250px;
  height: 250px;
  background: url(https://lesspestcontrol.com.au/wp-content/uploads/green-tick.png) no-repeat;
  cursor: pointer;
  border: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>

<head>
</head>

<body>
  <input id="button" type="button" name="button" value="Search" class="button" />
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...