簡體   English   中英

如何自動填寫淘汰表

[英]How to automate filling out knockout form

您好,我目前在我的chrome開發工具中有一個包含以下部分的網站

<div class="itemEditorField-inputsRelation">
   <input class="details-relativeInput-ageOnset js-relativeInput-ageOnset" type="number" data-bind="numeric: ageOnset, attr: { min: 0, max: 999, placeholder: 'Age' }" min="0" max="999" placeholder="Age"></input>
</div>

我如何模擬在淘汰表輸入字段中輸入文本? 我努力了 ...

e = $.Event('keydown');e.keyCode=50;$('input.details-relativeInput-ageOnset.js-relativeInput-ageOnset').trigger(e);

但是它返回的只是對象本身。 我沒有代碼本身可以插入任何東西。 我只有Chrome和JQuery可以使用。 任何幫助將不勝感激。 謝謝。

如果您具有普通value綁定,則技巧將是觸發輸入字段的change觸發器。 這可能對您有用,但是很難說,因為您有一個numeric綁定,它不是標准的綁定處理程序,而是自定義的處理程序。 無論什么事件導致綁定變量被更新,這都是您要觸發的。

下面是帶有value綁定的演示。

 var vm = { ageOnset: ko.observable('') }; vm.ageOnset.subscribe(function(newValue) { alert("New value:" + newValue); }); ko.applyBindings(vm); setTimeout(function () { $('input').val('12').change(); }, 500); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script> <div class="itemEditorField-inputsRelation"> <input class="details-relativeInput-ageOnset js-relativeInput-ageOnset" type="number" data-bind="value: ageOnset, attr: { min: 0, max: 999, placeholder: 'Age' }" min="0" max="999" placeholder="Age" /> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM