如果成功,我该如何启用下一个按钮?

时间:2017-12-27 05:57:53

标签: javascript jquery html vue.js

这是我点击移动到下一个标签的按钮

<button type="submit" class='btn btn-next btn-primary' name='next' value='Next'>Next</button>

如果状态为真,我该如何启用?

success: function(e) {
  if (e.status) {
    alert("Success")
    vm.pid = e.pid;
    console.log(vm.pid);
  } else {
    vm.response = e;
    alert("Registration Failed")
  }
}

仅当alert = success?

时,如何移至下一个标签页?

3 个答案:

答案 0 :(得分:0)

试试这个,

编写了一个示例函数..默认情况下它会被禁用,如果你写了一些按钮就会启用。没有jquery使用原生javascript

&#13;
&#13;
document.getElementById("next").disabled = true;
function do_enable(e=true) {
    if (e)
    {
     alert("Success")
      /*vm.pid=e.pid;
      console.log(vm.pid);*/
      document.getElementById("next").disabled = false;
      
  }
    else {
      vm.response = e;

     alert("Registration Failed") 
    }
}
&#13;
<input type="text" id="status" onchange="do_enable()" placeholder="say something">
<button type="submit" id="next" class='btn btn-next btn-primary' name='next' value='Next'>Next</button>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用:disabled启用或禁用使用Vue的按钮。 Read more.

  <button type="submit" class='btn btn-next btn-primary' name='next' value='Next' :disabled="isDisabled">Next</button>

  success: function(e) {
          if (e.status)
          {
           alert("Success")
            vm.pid=e.pid;
            console.log(vm.pid);
            vm.isDisabled = false; //enable button

        }
          else {
            vm.response = e;
            vm.isDisabled = true; //disable button

           alert("Registration Failed") 
          }
      }

<强>更新 不要忘记在vue isDisabled对象

中添加data
data: {
   isDisabled: false
}

答案 2 :(得分:0)

这样做

success: function(e) {
  if (e.status) {
    alert("Success")
    vm.pid = e.pid;
    console.log(vm.pid);
  } else {
    vm.response = e;
    alert("Registration Failed")
    e.preventDefault();//do this it can prevent your from to next tab

  }
}