English 中文(简体)
Jquery:根据选择小部件中选择的选项,如何取消隐藏特定的div?
原标题:Jquery: How do I unhide a specific div, depending on what option is selected in a select widget?
  • 时间:2011-02-14 12:54:35
  •  标签:
  • jquery

我正试图找到在选择小部件中显示与特定选项相对应的文本的最佳方式。我想我可以用文本填充多个div,每个div对应于select小部件中的一个选项,并在最初用“display:none”设置它们。然后使用Jquery,我会将特定的div取消设置为“display:none”,这取决于选择了哪个选项。然而,我是Jquery的新手,不知道从哪里开始。有人能为我指明正确的方向和/或就更好的方法给我建议吗?

最佳回答

我通常这样解决问题

<select id="select">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

<div class="my-div-class" id="my-div-id-1">blah 1</div>
<div class="my-div-class" id="my-div-id-2">blah 2</div>
<div class="my-div-class" id="my-div-id-3">blah 3</div>

然后我将执行这段jquery代码

$( #select ).change(function() {
  $( .my-div-class:visible ).hide();
  $( #my-div-id-  + $( #select ).val()).show();
});

这些只是例子。你可以随心所欲地概括。。。

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签