小编Svi*_*lev的帖子

反应.onCopy事件的preventDefault()不起作用

我试图找出如何使falseonCopy事件上的剪贴板事件返回.我用它来测试onCopy处理程序和e.preventDefault()方法.但文本被无限制地复制到缓冲区!我想念的是什么?

先感谢您.

import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import ReactDOMServer from 'react-dom/server';
import './index.css';


class Copy extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      time: '',
      timer: false,
      counter: 0
    };

    this.handlerCopy = this.handlerCopy.bind(this);
  }

  handlerCopy(e) {

    e.preventDefault(); // must prevent the current event

    this.setState(prevState => ({
      counter: prevState.counter + 1
    }));

    alert('Don\'t copy it!');
  }

  render() {
    return (
      <React.Fragment>
        <p onCopy={this.handlerCopy}>Copy me!</p>
        <p>Copy count: {this.state.counter}</p> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

10
推荐指数
1
解决办法
1382
查看次数

accumulator.value()末尾的"Undefined"

我遇到了价值错位的问题constructor function method this.result.我不明白为什么我得到结束的结果function- undefined...

请告诉我,遗忘的内容包括function:(

function Accumulator(startingValue) {
    this.startingValue = startingValue;

    this.read = function() {
        this.a = +prompt('Your digit: ', '');
    };

    this.value = function() {
        this.value += this.a;
    };

    this.result = function() {
        return this.value + this.startingValue;
    }
}

var accumulator = new Accumulator(1); // starting value 1
accumulator.read(); // sum prompt with current value
accumulator.read(); // sum current prompt with previous prompt and current value
console.log( accumulator.result() ); // display …
Run Code Online (Sandbox Code Playgroud)

javascript constructor function

3
推荐指数
1
解决办法
61
查看次数

使用方法sort()对数组元素中的符号进行排序

我需要通过符号unicode cinema对数组元素进行排序arr(在输出中它必须像" aceinm ").我知道在这种情况下我们需要使用方法sort().但我知道如何为数组元素注入排序方法.

请帮忙.以下代码无效.

错误:arr [1] .sort不是函数.

var arr = ["cinema"];

arr[1].sort();
console.log(arr[1]);
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting

2
推荐指数
1
解决办法
115
查看次数

我在循环中忘记了什么?

我正在尝试table6行创建一个,但我无法理解我在for循环中做错了什么.

<script>
    var table = document.createElement('table');
    var tbody = document.createElement('tbody');
    var tr = document.createElement('tr');
    var td = document.createElement('td');

    document.body.appendChild(table);
    table.appendChild(tbody);

    for (var i = 0; i < 6; i++) {
      tbody.appendChild(tr); // makes only 1 row, but should make 6 rows
    }
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript loops

2
推荐指数
1
解决办法
47
查看次数

"React"不适用于全球范围

我无法弄清楚我做错了什么.我也读过关于SOF的几个问题,但其中任何一个都不适合我.

我有一堆错误:

第3行:当使用JSX react/react-in-jsx-scope时,
'React'必须在范围内第4行:当使用JSX react/react-in-jsx-scope时,'React'必须在范围内
第5行:'React'在使用JSX react/react-in-jsx-scope时必须在范围内
第9行:'ReactDOM'未定义no-undef

function tick() {
  const element = (
    <div>
      <h1>Hello, world!</h1>
      <h2>It is {new Date().toLocaleTimeString()}.</h2>
    </div>
  );
 
  ReactDOM.render(element, document.getElementById('root'));
}

setInterval(tick, 1000);
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

0
推荐指数
1
解决办法
1060
查看次数

如何将常量放在php中的数组中

我需要在WordPress页面上获取作者的数量.首先,这个问题不涉及WordPress语法或更多关于此CMS的内容.问题严格来说是php算法.

所以,我有10方法得到的元素foreach.而现在我必须把它们放在数组中$getcount,以便countphp语言中的数组方法来计算它们.

由于某些原因,方法count不起作用,因为我总是得到else结果.

<?php foreach ($coauthors_meta as $key ) :  
    $getcount = array($key);
    if (count($getcount) > 1) echo '<div class="privv">Hello!</div>';
    else echo 'Empty';
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)

PS数组方法foreach ($coauthors_meta as $key )工作正常,并在页面上显示所有作者.所以问题在于隐藏在其他方面.

php arrays wordpress

-1
推荐指数
1
解决办法
62
查看次数

标签 统计

javascript ×5

arrays ×2

reactjs ×2

constructor ×1

function ×1

html ×1

loops ×1

php ×1

sorting ×1

wordpress ×1