javascript - React.js 处理事件浏览器丢失

标签 javascript html css reactjs event-handling

我开始通过观看一些教程和文档来学习 React.js。一些我在 Google Chrome 上遇到这个问题的原因:

enter image description here

在 Firefox 中,它不显示任何内容,应该显示代码中的信息。

HTML

<!DOCTYPE html>
<html>
<!-- jQuery, jQuery.ui -->
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<!-- React -->
<script src="https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.3284-6/11057025_805715566176382_77439371_n.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.29/browser.js"></script>

<!--Custom Styles -->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>React Bulletin Board</title>
</head>
<body>
<div id="react-container"></div>
<script src="js/Note.js" type="text/babel" ></script>
</body>
</html>

JavaScript

var Note = React.createClass({

    edit: function() {

        alert('editing note');

    },

    remove: function() {

        alert('removing note');

    },

    render: function() {

        return (

            <div className="note">

                <span>

                    <button className="btn btn-primary glyphicon glyphicon-pencil"/>
                    <button className="btn btn-danger glyphicon glyphicon-trash"/>

                </span>

            </div>

        );

    }

});

React.render(<Note>Hello World</Note>, 
    document.getElementById('react-container'));

CSS

@import url(http://fonts.googleapis.com/css?family=Shadows+Into+Light);

body,
html,
div.board,
div#react-container {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
}

div.board {
    background-color: brown;
    width: 100%;
    background: #eab92d;
    background: -moz-radial-gradient(center, ellipse cover, #eab92d 57%, #c79810 99%);
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(57%, #eab92d), color-stop(99%, #c79810));
    background: -webkit-radial-gradient(center, ellipse cover, #eab92d 57%, #c79810 99%);
    background: -o-radial-gradient(center, ellipse cover, #eab92d 57%, #c79810 99%);
    background: -ms-radial-gradient(center, ellipse cover, #eab92d 57%, #c79810 99%);
    background: radial-gradient(ellipse at center, #eab92d 57%, #c79810 99%);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eab92d', endColorstr='#c79810', GradientType=1);

}

div.note {
    height: 150px;
    width: 150px;
    background-color: yellow;
    margin: 2px 0;
    position: relative;
    cursor: -webkit-grab;
    -webkit-box-shadow: 5px 5px 15px 0 rgba(0, 0, 0, .2);
    box-shadow: 5px 5px 15px 0 rgba(0, 0, 0, .2);
}

div.note:active {
    cursor: -webkit-grabbing;
}

div.note p {
    font-size: 22px;
    padding: 5px;
    font-family: "Shadows Into Light", Arial;
}

div.note:hover > span {
    opacity: 1;
}

div.note > span {
    position: absolute;
    bottom: 2px;
    right: 2px;
    opacity: 0;
    transition: opacity .25s linear;
}

div.note button {
    margin: 2px;
}

div.note > textarea {
    height: 75%;
    background: rgba(255, 255, 255, .5);
}

.glyphicon-plus {
    position: fixed;
    top: 10px;
    right: 10px;
}

我不明白为什么我在两个浏览器中都缺少信息。该信息应该会出现,因为这是教程代码的一部分。

最佳答案

这是一个跨源问题。您可能正在尝试使用 file://或 C:\从本地驱动器加载 Note.js。要使用跨源请求,您需要在计算机上安装 Web 服务器。查看 express.js 和此示例,了解如何在您的计算机上设置简单的 node.js Web 服务器:https://expressjs.com/en/starter/hello-world.html

关于javascript - React.js 处理事件浏览器丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597414/

相关文章:

javascript - 更改文本节点的样式但不更改子节点

android - 从简单的 html5 + javascript 游戏创建 iOS 和 Android 应用程序?

javascript - 如何将输出值显示为文本?

javascript - 单击将单选按钮值插入 mysql

css - 为什么表格单元格中 'absolute' 定位的 DIV 元素的一部分未显示(仅在 Google Chrome 中)

javascript - Angular Bootstrap 正在创建重复的 Bootstrap 模式

javascript - 在 Angular DOM 操作后执行 Javascript

javascript - 如何检测已安装的 Chrome 版本?

jquery - 如果单击除第一个链接以外的所有链接,我想让一个对象有一个类处于事件状态,如果单击第一个链接,则应将其删除(如果处于事件状态)

html - 使用首选项(不是 CSS 或 JS)关闭 WebKit 大纲