简单的 div 根据菜单选择隐藏或显示
这应该很容易......但我花了一天的大部分时间试图弄清楚它。使用 jQuery:代码是这样的:
<tr>
<select name="exist_author" class="exist_author">
<option value="select">Select</option>
<option value="new_auth">I cant find my author</option>
<option value="2">Tom Wolf</option>
<option value="1">Frank Baum</option>
</select>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$("#new_author").css("display","none");
$(".exist_author").change(function(){
var test = $(this).val();
if(test !== 'new_auth') {
$("#new_author").fadeOut("slow");
}
else {
$("#new_author").fadeIn("slow");
}
});
});
</script>
<tr id="new_author">Text to Show on 'I cant find my author' menu selection</tr>
我已经淡入以处理选择,但它立即淡出。
This should be easy...but I have spent the better part of the day trying to figure it out. Using jQuery: The code is like this:
<tr>
<select name="exist_author" class="exist_author">
<option value="select">Select</option>
<option value="new_auth">I cant find my author</option>
<option value="2">Tom Wolf</option>
<option value="1">Frank Baum</option>
</select>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$("#new_author").css("display","none");
$(".exist_author").change(function(){
var test = $(this).val();
if(test !== 'new_auth') {
$("#new_author").fadeOut("slow");
}
else {
$("#new_author").fadeIn("slow");
}
});
});
</script>
<tr id="new_author">Text to Show on 'I cant find my author' menu selection</tr>
I have gotten the fade in to work on the selection, but it immediately fades back out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎不支持淡出 TR,请尝试以下操作:
Looks like fading a TR isn't supported, try this:
我希望您为了简单起见省略 td 标签,否则它根本就不是一个有效的 html。我真的不明白为什么你需要使用表格而不是 div。
无论如何,在必须显示文本的 td 标签内,将该文本放入 div 中,并为其指定一个 id“new_author”(从 tr 标签中删除该 id)。
另外,不要将脚本放在 tr 标记之间。要么把它放在 head 部分,要么放在关闭 body 标签之前。
I hope you're omitting td tags for the sake of simplicity, otherwise it's simply not a valid html. And I really don't understand why you need to use a table at all instead of divs.
Anyway, within your td tag that has to show text, put that text in a div, and giv it an id "new_author" (remove that id from tr tag).
Also, don't put script between the tr tags. Either put it in the head section or right before closing body tag.