在我的情况下,如何使用jQuery隐藏和显示? [英] How to hide and show in my case using jQuery?

查看:97
本文介绍了在我的情况下,如何使用jQuery隐藏和显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery的新手.我有一个 index.html 页面,

I am new to jQuery. I have a index.html page,

<body>
  <div id="content">
</body>

我希望此功能在页面加载时,内容"区域显示一个列表:

I would like the feature that when page loaded, "content" area shows a list:

<div id="my-list">
    <select id="carlist" size="10">
          <option>BMW</option>
          <option>TOYOTA</option>
          <option>SKODA</option>
    </select>
</div>

当用户从列表选项中选择汽车时,列表"my-list"消失(隐藏),并且图像显示在""区域.

when user select a car from the list option, the list "my-list" disappear(hide), and an image will be shown in the "content" area.

这将隐藏选择内容,并在同一"content"区域中显示图像.

That's hide the selection filed and show the image in the same "content" area.

如何在jQuery中做到这一点?

How to do that in jQuery?

我尝试过:

var mylist=$('#my-list');
mylist.change(function(){
    mylist.hide()
    SOMEIMAGE.show()
}

但是,在何处定义"my-list"和image在同一"content"区域中?如何实现这一切?

But, where to define "my-list" and the image are in the same "content" area? How to implement this all?

推荐答案

var mylist=$('#carlist');
mylist.change(function(){
    mylist.hide();
    var container = mylist.parent();
    container.find('img').remove();
    container.append('<img src="x.jpg" />');
}

这篇关于在我的情况下,如何使用jQuery隐藏和显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆