heat.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var oSw_btn
  2. function show_heat_img(oHeatsw, status){
  3. if (status) {
  4. oHeatsw.src = "img/switch_off.png";
  5. } else {
  6. oHeatsw.src = "img/switch_on.png";
  7. }
  8. }
  9. function set_heat_switch(oHeatsw, status){
  10. if (oHeatsw.src.match('on')) {
  11. oHeatsw.src = "img/switch_off.png";
  12. } else {
  13. oHeatsw.src = "img/switch_on.png";
  14. }
  15. }
  16. var url = window.location.href
  17. console.log("当前页面地址:" + url)
  18. function get_status(root_url, oHeatsw){
  19. console.log("get_status :" + url)
  20. var url_staus = root_url + 'status';
  21. var request = new XMLHttpRequest();
  22. request.open('GET', url_staus);
  23. // 等待获取成功 onreadystatechange
  24. request.onreadystatechange = function(){
  25. if (request.readyState == 4 && request.status == 200){
  26. var res_status = JSON.parse(request.responseText)
  27. show_heat_img(oHeatsw, res_status['heat']['status']);
  28. }
  29. }
  30. request.send(null)
  31. }
  32. function my_function() {
  33. // window.alert('onload1');
  34. oLisw = document.getElementById("lisw");
  35. oHeatsw = document.getElementById("heatsw");
  36. get_status(url, oHeatsw)
  37. oHeatsw.onclick = function() {
  38. };
  39. };
  40. window.onload = my_function