Recently I have been working with the Chrome Plugin API and I am looking to develop a plugin which will make life easier for me for managing a website.
Now what I wish to do is to fire an event when a certain checkbox is checked.
As this website does not belong to me I cannot change the code therefore I am using the Chrome API. One of the main problems is that rather than there being an ID, there is a Name. I was wondering if I could fire the function once the certain checkbox with the 'name' is checked.
Thanks
解决方案
Assuming you're using this markup:
Without jQuery
Using the jQuery-like querySelector.
var checkbox = document.querySelector("input[name=checkbox]");
checkbox.addEventListener( 'change', function() {
if(this.checked) {
// Checkbox is checked..
} else {
// Checkbox is not checked..
}
});
With jQuery
$('input[name=checkbox]').change(function(){
if($(this).is(':checked')) {
// Checkbox is checked..
} else {
// Checkbox is not checked..
}
});