键盘输入有效,但更改输入值则不然

时间:2018-02-21 04:00:40

标签: javascript jquery html

所以我一直在尝试根据用户的策略编写一个赌注在赌博网站(gamdom)上的脚本。在现场,有一个输入与下注大小编号和一个下注按钮。

我试图用.val(),attr()更改输入值,同时添加.trigger()和我搜索的其他内容,但是当你点击按钮下注时,它会获得用户写的值无论如何用键盘。我真的不明白为什么,我真的很感谢你的帮助。

//leave page active
Object.defineProperty(document, "hidden", { value : false});
//Arrive js from github(didnt include here becouse it's large);


function randomInteger(min, max) {
    var rand = min - 0.5 + Math.random() * (max - min + 1);
    rand = Math.round(rand);
    return rand;
}   

//fakeClick from StackOverflow
function fakeClick(event, anchorObj) {
  if (anchorObj.click) {
    anchorObj.click()
  } else if(document.createEvent) {
    if(event.target !== anchorObj) {
      var evt = document.createEvent("MouseEvents"); 
      evt.initMouseEvent("click", true, true, window, 
          0, 0, 0, 0, 0, false, false, false, false, 0, null); 
      var allowDefault = anchorObj.dispatchEvent(evt);
      // you can check allowDefault for false to see if
      // any handler called evt.preventDefault().
      // Firefox will *not* redirect to anchorObj.href
      // for you. However every other browser will.
    }
  }
}

(() => {
    let startingsum = 500;
    let bettingsum = startingsum;
    let betdistance;

    function StartBetting(){
        betdistance = randomInteger(10,25);
        //if a roll passed
        $(document).arrive(".recentBustsContainer a", function() {
            betdistance--;
            //bet
            if(betdistance == 0)
            {
                //value is changing,but bet value does not
                $('.bet-input-div .form-control').attr('value', '100');
                //$('.bet-input-div .form-control').val('100');
                fakeClick(event, document.getElementsByClassName('bet-button')[8]);
            }
            //check if you win
            else if(betdistance == -1)
            {
                let str = $(this).text();
                let mult = parseFloat(str.substring(0, str.length - 1));
                //...
            }
        });
    }
    StartBetting();

})();

1 个答案:

答案 0 :(得分:0)

尝试

$('.bet-input-div .form-control').value = 'abc';

假设您的选择器是正确的