最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - alert() in DIV's onclick is not displayed after click - Stack Overflow

programmeradmin4浏览0评论

I have two rectangles with some text inside. I would like to display a different alert when I click on each one, but code below doesn't work (alert is not displayed). Any ideas? Thanks

<div id="panel0" style="width: 100%">
    <div class="titleBox" id="rect0" onclick="alert('yeah1');"
        style="height: 85px; width: 85px;">Hello</div>
    <div class="titleBox" id="rect1" onclick="alert('yeah2');"
        style="height: 85px; width: 85px;">Hello</div>
</div>

I have two rectangles with some text inside. I would like to display a different alert when I click on each one, but code below doesn't work (alert is not displayed). Any ideas? Thanks

<div id="panel0" style="width: 100%">
    <div class="titleBox" id="rect0" onclick="alert('yeah1');"
        style="height: 85px; width: 85px;">Hello</div>
    <div class="titleBox" id="rect1" onclick="alert('yeah2');"
        style="height: 85px; width: 85px;">Hello</div>
</div>
Share Improve this question edited Mar 3, 2017 at 6:45 KishanCS 1,3772 gold badges19 silver badges41 bronze badges asked May 18, 2012 at 8:31 user411103user411103 12
  • 4 your code works: jsfiddle/Cyx2n – Andreas Wong Commented May 18, 2012 at 8:32
  • @user411103 Your code is working for me too... – Exception Commented May 18, 2012 at 8:33
  • There's no problem with this code – Narayan Singh Commented May 18, 2012 at 8:33
  • 2 is JS enabled on your machine/browser? – Massimiliano Peluso Commented May 18, 2012 at 8:33
  • 1 @DavidMårtensson Why?! ...user411103: Yes, for sure. – lorenzo-s Commented May 18, 2012 at 9:56
 |  Show 7 more ments

1 Answer 1

Reset to default 3

Try this

<div id="rect0" onclick="alert('yeah1');" style="height: 85px; width: 85px; background-color: #ff0000;">
     Hello
</div>                        
发布评论

评论列表(0)

  1. 暂无评论