【问题标题】:changing the text of the button when clicking them单击按钮时更改按钮的文本
【发布时间】:2017-01-14 19:48:55
【问题描述】:

下面是我的html代码中的一个按钮!

<input type='button'onclick='change()' id='processorder'  class='btn btn-success' value='Process order'>"

以下是我用来改变按钮被点击时文本的javascript函数!(从处理顺序到完成)!

var elem = document.getElementById("processorder");
if (elem.value=="Process order") elem.value = "Process order";
else elem.value = "Complete";

虽然上述功能似乎是正确的,但它不起作用!我该如何纠正这个问题?

【问题讨论】:

  • 你的 if/else 被颠倒了......如果“处理顺序”,那么让它“处理顺序”就是它现在的读取方式,让它看起来永远不会改变

标签: javascript html button text onclick


【解决方案1】:

我猜你正在尝试这个:

var elem = document.getElementById("processorder"); if (elem.value=="Process order") elem.value = "Complete"; else elem.value = "Process order";

如果值是流程订单,那么您必须更改该值才能完成,否则它应该是流程订单。

我在这里做了一个简单的示例:https://jsfiddle.net/fj4v4wqp/

【讨论】:

  • 非常感谢!如果我想使用javascript更改此按钮“完成”的文本,如何实现?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-08
  • 2022-01-08
  • 2023-02-07
  • 1970-01-01
相关资源
最近更新 更多