问题照片[如果我的下面说明令人困惑,请参考此处) http://imgur.com/a/t2nkD
我试图从页面获取值(答案)并将这些值(答案)注入同一页面上的文本区域。到目前为止,这个脚本能够做到这一点,但即使正确的值(答案)输入到文本区域,检查答案结果在页面告诉我它是不正确的。
但是,如果我输入,请说“空格”。在注入所有正确值(答案)之后的每个文本区域中,然后重新检查答案,答案返回正确。
此外,物理点击文本区域并按Enter键会导致输入错误,但是再次单击在同一文本区域中输入则会更改答案以进行更正。
我对jquery不熟悉,或javascript实际上这是我第一次使用jquery。 但是,我想到的一些可能的问题是:
在用户点击文字区域并在框中输入内容之前,文本区域不会更新
2a上。我尝试使用.focus
,.sendkeys
和按键事件来模拟用户在框中输入内容。 (没有工作)
最终,我打算这样做,以便它自动提交所有答案,这不应该太难。
所以我想我的主要问题是,即使文本区域的值已被
更改,我如何更新文本区域的值? $( txtArea ).eq(h).val(ansTrim);.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse)
{
if( request.message === "clicked_browser_action" )
{
//Amount of text-area elements on page (found by class)
var n = $(
'.ember-view.ember-text-area.question-answer-textarea.min-width-text-area'
).length;
for (var i = n; i >= 0; i--)
//click "Show Answer" for the amount of text-area elements there are
{
//The page requires you click Show Answer twice to confirm that you
//want to see the answer
$( ".ember-view.question-answer-show-button" ).eq(i).click();
$( ".ember-view.question-answer-show-button" ).eq(i).click();
for (var h = 0; h <= n; h++)\
{
//save all elements with the class
var txtArea = $(
".ember-view.ember-text-area.question-answer-textarea.min-width-text-area"
);
//after answer is revealed stores the answer's text in firstAnswer
var firstAnswer = $( ".question-answer" ).eq(h).text();
//Orange check button stored in submitBTN for later functionality
var submitBTN = $(".ember-view.question-answer-check-button")
//Originally I thought that the answers weren't going through because
//the string saved in firstAnswer had an additional space
//in front and on the end
var ansTrim = $.trim(firstAnswer);
//store keypress event in var press
var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 32;
console.log(ansTrim);
//Fill each text area with the respective answer
$( txtArea ).eq(h).val(ansTrim);
/*
$(submitBTN).click(function() {
$(txtArea).change();
});
*/
//Above is my attempt at updating the textboxes with the values
//in them (didn't work)
}
}
}
}
);