简体   繁体   English

为什么单击按钮时按钮的样式会发生变化?

[英]Why does my button's style change when I click on it?

在此处输入图像描述

I edited my buttons' style, but when I click on one, a function is called and changes the value (via ajax, if that affects anything), but the button changes as on the image.我编辑了按钮的样式,但是当我单击一个按钮时,会调用 function 并更改值(通过 ajax,如果这会影响任何内容),但按钮会像图像上一样更改。 This is my code:这是我的代码:

$(document).ready(function() {
  $(':button').on('click', function(event) {
    $('#ID').val(this.id);
    var tmp = this.id;
    $.ajax({
      type: $('#klik').attr("method"),
      url: $('#klik').attr("action"),
      data: $('#klik').serialize(),
      success: function(d) {
        alert(d)
        $('#' + tmp).val(d);
        const button = document.getElementById(tmp);
        button.disabled = true;
        if (d == 'bomba') {
          alert('bb');
        }

      },
      error: function() {
        alert('Greska')
      }
    });
  });
});
var docFrag = document.createDocumentFragment();
for (var i = 0; i < 9; i++) {
  var row = document.createElement("tr")
  for (var j = 0; j < 9; j++) {
    var elem = document.createElement('input');
    elem.className = 'gumb';
    elem.type = 'button';
    elem.id = 'r' + i + 's' + j;
    elem.value = '';
    elem.innerHTML = elem.value;
    docFrag.appendChild(elem);
  }
  document.body.appendChild(docFrag);
  document.body.appendChild(row);
}

This is my CSS:这是我的 CSS:

.gumb {
  width: 50px;
  height: 50px;
  background-color: blue;
  text-align: center;
  font-size: 25px;
  color: white;
  margin-bottom: 10px;
}

You need to align the text.您需要对齐文本。 Something like this:像这样的东西:

.gumb { vertical-align: middle; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 if 语句在我手动更改选中状态时有效,但在单击按钮时无效 - Why does my if statement work if I manually change the checked state, but not when I click the button 为什么当我更改它的 id 属性时我的按钮没有点击? - Why does my button not click when I change its id attribute? 为什么单击按钮后我的数据文件无法更改? - Why my data file cannot change when I click on the button? 当我点击它时,按钮颜色不会改变? - Button color does not change when I click on it? 当我点击按钮时,它什么也没做 - My button does nothing when i click on it 为什么当我的页面加载而不是单击我的单选按钮时触发我的 onchange 事件? - Why does is my onchange event triggered when my page loads instead of when I click my radio button? <button>当我按下 Enter 时,</button>为什么会触发“click”事件<button>?</button> - Why does a `click` event get triggered on my <button> when I press Enter on it? 当我单击按钮时,为什么我的角度应用程序会刷新数据源中的所有行? - Why does my angular app refresh all rows from the data source when I click a button? 为什么在更改按钮类后点击功能不起作用? - Why does the click function not work after I change the class of a button? 如果将按钮放入SubmitHandler,为什么我的按钮在jquery中单击两次? - Why does my button click twice in jquery if I put it in submitHandler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM