简体   繁体   English

JavaScript更改提交表单上的输入样式

[英]JavaScript changing input style on submit form

I am trying to make same loading animation at the background of input when a form is submitted. 提交表单时,我试图在输入的背景下制作相同的加载动画。

css: CSS:

.inputLoading {
  background-image: url("../img/loading.gif");
  background-repeat: no-repeat;
  background-position: 99% 50%;
}
.form-control {
  display: block;
  width: 100%;
  height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.42857143;
  color: #555555;
  background-color: #ffffff;
  background-image: none;
  border: 1px solid #cccccc;
  border-radius: 4px;
}

javascript: JavaScript的:

function onSearch(){
    document.getElementById("loadingAnimation").className += " inputLoading";
}

html: HTML:

<form action="index.php" method="get" onsubmit="onSearch()">
    <input type="text" id="loadingAnimation" class="form-control">
    <button type="submit">Search</button>
</form>

Problem is that this works in IE11 and Firefox 26 but not in Chrome 33. In Chrome there is no animation after form is submitted. 问题是这在IE11和Firefox 26中有效,但在Chrome 33中无效。在Chrome中,提交表单后没有动画。 URL to gif is correct. gif的网址正确。 So I try to resolve the problem but no luck. 因此,我尝试解决问题,但是没有运气。 It is strange that if I change only background color of input it will work everywhere. 奇怪的是,如果仅更改输入的背景色,它将在任何地方都有效。

Any ideas? 有任何想法吗?

UPDATE: I have tested this on several computers and now I can tell that there is not problem only in Chrome. 更新:我已经在多台计算机上对此进行了测试,现在我可以说仅在Chrome中没有问题。 On some computers do not work even on FF or IE. 在某些计算机上,即使在FF或IE上也不起作用。

Make sure if any kind of adBlock extension or image block extension is installed on you chrome browser. 确保您的Chrome浏览器上安装了任何类型的adBlock扩展名或图像块扩展名。 It may be one of the reasons if image is not being displayed. 如果没有显示图像,可能是原因之一。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM