Jump to content
  • 0

Проблема со скриптом jquery


samec1337
 Share

Question

Здравствуйте!

Столкнулся с проблемой, код в script на кнопке Stop не работает, если он лежит в отдельном файле скрипта. Если засунуть в html то работает.

А старт запускается автоматически при загрузке страницы, хотя я к нему не обращался.

<!DOCTYPE html><html><head><meta charset="utf-8"><script src="jquery-2.1.4.js"></script><style>body {  font-family: fantasy;  transition-property: backround;  transition-duration: 1s;} input {  background-color: white;  text-align: center;  border-radius: 15px;  margin: 10px 10px 10px 40px;  font-size: 20px;  width: 120px;} #buttons {  margin-top: 20px;}</style></head><body>  <input id="clock"><br>  <input type="button" id="btnStart" value="Start"><br>  <input type="button" id="btnStop" value="Stop">  <script>  $("#btnStart").click(setInterval(function() {    var clock = new Date();    var clockString = (String(clock).substring(15, 24));    var color = "rgb(" + (Math.round(Math.random(255, 0) * 255)) + ", "     + (Math.round(Math.random(255, 0) * 255)) + ", "     + (Math.round(Math.random(255, 0) * 255)) + ")";     $("body").css("background-color", color);     document.getElementById("clock").value = clockString;  }, 1000));  $('#btnStop').click(function(){    location.reload();  });  </script></body></html>
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy