我正在嘗試使用click()
的函數。我在控制檯中沒有得到任何錯誤,我怎樣才能做到這一點,當點擊發生時,它會執行該功能中的操作?這是我正在使用的代碼。使用click()函數javascript
inputIds = [].filter.call(document.getElementsByTagName('input'), function(el) {
return el.id.indexOf('ansx') === 0;
}).map(function(el) {
return el.id;
});
// random number between low and high range
inputId = inputIds[Math.floor(Math.random() * inputIds.length)];
document.getElementById(inputId).click(function() {
chrome.extension.sendMessage({ message: "text here" }, function(response) {
return response;
});
});
那麼,這是行不通的?很確定,'返回響應'實際上並沒有做任何事情。 – 2012-08-01 18:41:09
@火箭他們單獨工作,但如果我嘗試使用上面的代碼,它不會 – 2012-08-01 18:47:02
您正在隨機選擇一個ID。愚蠢的問題,但你想點擊正確的元素? – 2012-08-01 19:04:55