Javascript相当于Jquery的隐藏和显示 [英] Javascript equivalent of Jquery hide and show

查看:68
本文介绍了Javascript相当于Jquery的隐藏和显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的隐藏和显示jquery代码,我想问一下,如果有这相当于JavaScript?这是我的代码。

I have a simple hide and show Jquery code and I want to ask if there is equivalent of this to javascript? Here's my code.

JQUERY:

JQUERY:

$(document).ready(function(){
$("#myButton").hide();
   $("#1").click(function(){
      $("#myButton").show();
         $("#myButton").click(function(){
         $("#myButton").hide();
        });
   });
});

HTML:

HTML:

<select>
<option id="1">Science</option>
</select>
<input type="button" value="Click" id="myButton"/>

我在下面的评论中关注了一些代码,但它不起作用:

I followed some codes in the comments below but it is not working:

javascript:

javascript:

<script>
    document.getElementById('myButton').style.display = 'none';
    function selectOptionsupdated(select){
    document.getElementById('myButton').style.display = 'block'; 
    }
</script>

html:

<select onSelect="selectOptionsupdated(this)">
<option id="1">Science</option>
</select>
<input type="button" value="Click" id="myButton"/>

我想要的是首先隐藏了按钮,当我点击< option> 标签科学按钮出现,当我点击按钮时,按钮被点击后被隐藏。如果还有更多< option> 标签?对不起,我还是个初学者。任何帮助将不胜感激。

What I want is at first the button is hidden, and when I click the <option> tag "Science" the button appears and when I click the button, the button is hidden after it is being clicked. And what if there are more <option> tags? Sorry i'm still a beginner. Any help will be appreciated.

推荐答案

这很简单

document.getElementById('myElement').style.display = 'block'; // show
document.getElementById('myElement').style.display = 'none'; // hide

添加 onSelect =selectOptionsupdated(this)在您的选择

然后

then

function selectOptionsupdated(select){
//do your stuff here  
}

这篇关于Javascript相当于Jquery的隐藏和显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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