4

私のCSS:

#a_x200{
    visibility: hidden;
    width: 200px;
    height: 200px;
    background-color: black;
}

私のJS:

<script type="text/javascript">
    function show(id) {
        document.getElementById(id).style.display = 'block';
    }
</script>

私のHTML

<div id="a_x200">asd</div>
<innput type="button" class="button_p_1" onclick="show('a_x200');"></input>

動作しない私は何かを逃したと思います!

4

6 に答える 6

11

これを試して:

document.getElementById('a_x200').style.visibility = 'visible';
于 2012-12-12T09:45:22.670 に答える
3

このコードを試すことができます:

HTML Code:
        <div id="a_x200" style="display:none;">asd</div>
        <input type="button" class="button_p_1" onclick="showStuff('a_x200');"></input>

Java script:

<script type="text/javascript">
function showStuff(id) {
        document.getElementById(id).style.display = "block";
}
</script>

このコードを試してみてください。問題が解決します。

于 2012-12-12T10:02:03.920 に答える
2

を使用して非表示にしてから、 CSSプロパティをvisibility: hidden使用して表示しようとしています。displayこれらは2つの完全に別個のプロパティであり、一方を変更しても他方は魔法のように変更されません。

再び表示したい場合は、visibilityプロパティの値を次のように変更しvisibleます。

document.getElementById('a_x200').style.visibility = 'visible';
于 2012-12-12T09:45:16.283 に答える
2

ここでは、jqueryを使用してjquery Show/Hideで作成した1つの例を見ることができます。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<style>
.slidingDiv {
    height:300px;
    background-color: #99CCFF;
    padding:20px;
    margin-top:10px;
    border-bottom:5px solid #3399FF;
}

.show_hide {
    display:none;
}

</style>
<script type="text/javascript">

$(document).ready(function(){

        $(".slidingDiv").hide();
        $(".show_hide").show();

    $('.show_hide').click(function(){
    $(".slidingDiv").slideToggle();
    });

});

</script>

<a href="#" class="show_hide">Show/hide</a>
<div class="slidingDiv">
Fill this space with really interesting content. <a href="#" class="show_hide">hide</a></div>​
于 2012-12-12T09:55:43.470 に答える
1

あなたの入力は見当違いです

このようにする必要があります:

私のJS

<script type="text/javascript">
function showStuff(a_x200) {
        document.getElementById(a_x200).style.display = 'block';
}
</script>

私のHTML

<div id="a_x200">asd</div>
<innput type="button" class="button_p_1" onclick="showStuff('a_x200');"></input>
于 2012-12-12T09:43:31.090 に答える
1

これを試して...

function showStuff(id) {
    document.getElementById(id).style.display = 'block'; // OR
    document.getElementById(id).style.visibility = 'visible'; 
} 

編集

ボタンに気付いた場合は、をクリックしてくださいonclick="showStuff('a_x200');"。あなたはすでにidをパラメータとしてあなたの関数に送っています。それで私はパラメータを取り、それを使用しています。

あなたの場合、パラメータはありますが、それを使用していません...同じことをしますが...

またはあなたはこれを行うことができます

<input type="button" class="button_p_1" onclick="showStuff();"></input>  // omitting double 'n'

function showStuff() {
    document.getElementById('a_x200').style.display = 'block';
}  // missing curly bracket 

これは両方とも同じことをします

于 2012-12-12T09:43:55.863 に答える