新手:如何使用jQuery在我的案例中隐藏和显示? [英] Newbie: how to hide and show in my case using jQuery?

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

问题描述

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

I am a newbie in 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-列表消失(隐藏),内容显示 >地区。

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.

隐藏选择的内容并将图像显示在相同的内容区域内。

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 图像在同一个内容区域?如何实现这一切?

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天全站免登陆