当我调用其他函数时,如何聚焦/单击按钮?

时间:2018-12-22 11:29:41

标签: angularjs angularjs-scope angular-promise

我有angular js脚本,这里我的页面是第一次加载,然后焦点在按钮上,现在的问题是1)第一次,当我调用的ng-change函数然后焦点在那个按钮上2)第二次3),但第三次不工作。这意味着焦点未设置为按钮或按钮未单击。

// This is my function which is called when ng-model value changed
 $scope.checkEneteredQuantity = function(qty,bagProduct,index){
      if(qty == 0){
        bagProduct.count = 1;
      }else{
      var qty = parseInt(qty);
      var nwqt = parseInt(qty); 
      var myflag = 0;
      if(qty > 0){

        myflag = 1;

      }else if(qty < 0){
        myflag = 2;
      }
      if(myflag == 1){
        if(bagProduct.return == "simple"){
           var cal = parseFloat(bagProduct.count * bagProduct.priceAftertax)
           if ((cal % 1) != 0){ 
            if(cal.toString().split(".")[1].length > 2){
              bagProduct.newpric = parseFloat(cal).toFixed(2);
            }else{
              bagProduct.newpric = cal;
            }
        }else{
            bagProduct.newpric = cal;
        }


        $("#output-text-bulk").click();// this is not working
    }

//这是我的按钮代码

 <button id="output-text-bulk" numeric-keyboard-input="" ng-model="simple"
         ng-bind="simple" style="padding: 10px;">
 </button>

//这是我的函数,当ng-model值更改时会调用

 $scope.checkEneteredQuantity = function(qty,bagProduct,index){
      if(qty == 0){
        bagProduct.count = 1;
      }else{
      var qty = parseInt(qty);
      var nwqt = parseInt(qty); 
      var myflag = 0;
      if(qty > 0){

        myflag = 1;

      }else if(qty < 0){
        myflag = 2;
      }
      if(myflag == 1){
        if(bagProduct.return == "simple"){
           var cal = parseFloat(bagProduct.count * bagProduct.priceAftertax)
           if ((cal % 1) != 0){ 
            if(cal.toString().split(".")[1].length > 2){
              bagProduct.newpric = parseFloat(cal).toFixed(2);
            }else{
              bagProduct.newpric = cal;
            }
        }else{
            bagProduct.newpric = cal;
        }


        $("#output-text-bulk").click();// this is not working
    }

当我的ng-change函数调用时,我想将焦点放在按钮上。

1 个答案:

答案 0 :(得分:0)

我认为您应该从所有范围中删除焦点代码,然后每次运行更改功能焦点代码并且您的按钮都可单击,或者检查条件(如果/其他)

b