How do I select an element with its name attribute in jQuery?
This question already has an answer here:
$('[name="ElementNameHere"]').doStuff();
jQuery supports CSS3 style selectors, plus some more.
See more
[attribute=""]
selector You can use:
jQuery('[name="' + nameAttributeValue + '"]');
this will be an inefficient way to select elements though, so it would be best to also use the tag name or restrict the search to a specific element:
jQuery('div[name="' + nameAttributeValue + '"]'); // with tag name
jQuery('div[name="' + nameAttributeValue + '"]',
document.getElementById('searcharea')); // with a search base
it's very simple getting a name:
$('[name=elementname]');
Resource:
http://www.electrictoolbox.com/jquery-form-elements-by-name/ (google search: get element by name jQuery - first result)
链接地址: http://www.djcxy.com/p/36258.html