无法以编程方式在olymptrade.com上的输入字段中输入值

问题描述 投票:0回答:1

我正在尝试以编程方式在网站上出价。想法相对简单,只需在输入字段中输入值,然后单击上或下按钮:

enter image description here

我已经尝试了一百万种不同的组合,例如:

 $(document).ready(
 function ()
      {
          bidEntryBox.value = "14"    //bidEnteryBox is an HTMLelement for the input field
          $(dealButtonUp).click()

          //I have also tried $(".input-currency__input").val = "14", does nothing
          //$(".input-currency__input").attr('value','14') does nothing
          //$(".input-currency__input").focus().trigger(jQuery.Event("keypress", { keyCode: 55 }))
          //^that didn't work either
      }
 )

上面未注释的示例确实改变了输入中的值,但是单击按钮只会放置在代码启动之前输入的任何值。单击输入字段只是将值更改回原来的值。在上述所有方法中,我通过在console.log中写入对象来确保获得正确的对象,因此我不会犯这个愚蠢的错误。这只是我写JavaScript代码的第二天,我感到非常沮丧。有指针吗?

这是输入元素的外观:

<input type="tel" autocomplete="off" class="input-currency__input" data-test="deal-amount-input" maxlength="9" value="1">
javascript google-chrome-extension dom-manipulation input-field
1个回答
0
投票

如果我正确理解了您的问题,我相信问题是您当前的代码几乎说了当文档加载完成时,将值设置为14,那么您将触发单击。这将触发click事件并导致您的输入被覆盖。

尝试一下:

    $(document.ready(function(){
      $(".input-currency__input" ).on( "click", function() {
        bidEntryBox.value = "14" 
       });
     });

[请看https://api.jquery.com/on/,这将使您对如何将事件附加到使用javascript和jQuery的动作有一些了解。

© www.soinside.com 2019 - 2024. All rights reserved.