Как сфокусировать / нажать кнопку при вызове моей другой функции? - PullRequest
0 голосов
/ 22 декабря 2018

У меня сценарий 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-модельзначение изменилось

 $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 голосов
/ 23 декабря 2018

я думаю, что вы должны получить свой код фокуса из всех областей, затем каждый раз, когда запускается ваша функция изменения, код фокуса запускается, и вы нажимаете кнопку, или проверяете ваше состояние (если / еще)

$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
            }
        }
    }
    $("#output-text-bulk").click();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...