怎么做一个数组按钮并排?

时间:2014-03-05 04:21:31

标签: javascript html wordpress

我是Java的新手,因为我试图在一周内学习我的课程项目。我正在通过wordpress创建一个网站,脚本按照我想要的方式工作。我不能移动按钮而不会弄乱一些东西而且它不再起作用。现在他们被堆叠在一起,但我希望他们并排

<button onclick="getThing()" type="button">Who?</button>
<button onclick="getArtStyle()" type="button">What?</button>

<div id="thing"></div>
<script type="text/javascript">
    // <![CDATA[
    var artArray = new Array("Poem", "Song", "Dance", "Drawing", "Story", "Painting",
        "Picture", "Play", "Bracelet", "Sign", "Joke", "Card", "Haiku", "Limerick", "Difference", "Doll", "Bathroom Graffiti", "Ghost Story", "Riddle", "Doodle", "Voodoo Doll", "Baked Good", "Replica");
    var thingArray = new Array("America", "Dad", "Mom", "Dog", "Dentist", "Parole Officer", "Cat", "Teacher", "Mailman", "Anyone", "Yourself", "Lover", "Professor", "Friend", "Frenemy", "Enemy", "Grandma", "Grandpa", "Somebody");

    function getArtStyle() {
        document.getElementById('answerDiv').innerHTML = artArray[Math.floor(Math.random() * artArray.length)];
    }

    function getThing() {
        document.getElementById('thing').innerHTML = thingArray[Math.floor(Math.random() * thingArray.length)];
    }
     // ]]>
</script>

1 个答案:

答案 0 :(得分:0)

试试这个:

<style>
    #thing, #answerDiv {
        display: inline-block;
    }
</style>

如果失败,请尝试:

<style>
    #thing, #answerDiv {
        float: left;
        clear: none;
    }
</style>

编辑:这假定当你说&#34;它们叠在一起时#34;你指的是结果<div>而不是按钮。否则,将#thing, #answerDiv替换为button

你的WordPress主题可能会让它们以清晰的方式浮动,或者(如果是按钮)显示为块(在前/后添加新行)。