我正在尝试使用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