如何遍历所有文本区域,不包括我有 id 的文本区域?
$("textarea").each(function (i, v) {
// i could use an "if" inside here, but would rather adjust the selector
});
我试过使用 :not($('#mySpecialTextarea'))
,但无法正常工作。
最佳答案
使用 jquery .not()
$("textarea").not('#mySpecialTextarea').each(function (i, v) {
// your code
});
您还可以使用 :not()
$("textarea:not('#mySpecialTextarea')").each(function (i, v) {
// your code
});
The
.not()
method will end up providing you with more readable selections than pushing complex selectors or variables into a:not()
selector filter. In most cases,.not()
is a better choice.
关于javascript - 在 .each 中排除一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375689/