切换问题
我已经搜索过这个论坛,但我无法找到任何可行的解决方案,我试图切换文本区域的可见性,但所有文本区域都被立即切换。我对 jquery 相当陌生,但这是我
jQuery(document).ready(function() { jQuery(".note").hide(); jQuery(".note_button").click(function() { jQuery(".note").fadeToggle("slow", "linear"); }); });使用此 html 的代码:
<table>
<tbody>
<tr>
<td colspan='2' class='product-name'>
</td>
<td>
</td>
<td></td>
<td class="cart-widget-remove">
</td>
</td>
</tr>
<tr>
<td colspan="6">
<form id="desc" action="" method="post" class="adjustform">
<div class="note">
<textarea name="" onfocus="this.value='';">Your optional note to the kitchen</textarea>
<input class="" type="button" value="Apply changes" />
<input class="" type="button" value="Cancel" />
</div>
</form>
I have searched this forum but i can't get any solutions to work, im trying to toggle a textarea visibility but all textareas are being toggled at once. im fairly new with jquery but here is my code
jQuery(document).ready(function() {
jQuery(".note").hide();
jQuery(".note_button").click(function() {
jQuery(".note").fadeToggle("slow", "linear");
});
});
to work with this html:
<table>
<tbody>
<tr>
<td colspan='2' class='product-name'>
</td>
<td>
</td>
<td></td>
<td class="cart-widget-remove">
</td>
</td>
</tr>
<tr>
<td colspan="6">
<form id="desc" action="" method="post" class="adjustform">
<div class="note">
<textarea name="" onfocus="this.value='';">Your optional note to the kitchen</textarea>
<input class="" type="button" value="Apply changes" />
<input class="" type="button" value="Cancel" />
</div>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果此模式在您的页面上多次出现
,那么您的选择器
jQuery('.note')
将选择所有 .note div。您需要为它们提供唯一的 ID 来选择单个 div 进行隐藏/显示或使用表单上已有的 ID。If this pattern shows up multiple times on your page
Then your selector
jQuery('.note')
will select all .note divs. You'll need to give them unique IDs to select individual divs for hiding/showing or use the id already on the form.看起来我们只有部分代码,但我会尝试一下...
jQuery 正在切换所有区域,因为您的选择器没有针对您想要专门切换的区域。假设您还有其他文本区域,这些文本区域也在带有“note”类的 div 内。如果这些 div 中的每一个都有一个唯一的类(例如“note-1”、“note-2”等),那么您可以选择要切换的特定文本区域。
It looks like we only have part of the code, but I'll give it a shot...
The jQuery is toggling all areas because your selector isn't targeting the one you want to toggle specifically. Presumably you have other textareas that also are inside divs with the class "note". If each one of these divs had a unique class (say "note-1", "note-2", etc.) then you could select the specific textarea you wanted to toggle.