小编mar*_*oxx的帖子

纯js的棋盘

我3天前在学校开始,我之前有一些C基础知识,所以这里的主要问题是语法(我认为).

目标是制作一个棋盘,8x8黑白方块,但我无法获得显示任何东西的代码.我错过了什么?

(html只有脚本src ="./ x.js"部分和"body"部分)

document.body.onload = addElement.innerHTML;

function addElement() {

    var newTable = document.createElement("table");
    for (var i = 1; i < 9; i++) {
        var newTr = document.createElement('tr');
        for (var j = 1; j < 9; j++) {
            var newTd = document.createElement('td');
            if (i % 2 == j % 2) {
                newTd.className = "white";
            } else {
                newTd.className = "black";
            }
            newTr.appendChild(newTd);
        }
        newTable.appendChild(newTr);
    }

    document.body.appendChild(newTable);

    document.getElementByClass("black").style.backgroundColor = "black";
    document.getElementByClass("white").style.backgroundColor = "white";
    document.getElementByTag("newTd").style.width = "25px";
    document.getElementByTag("newTd").style.height = "25px";
}
Run Code Online (Sandbox Code Playgroud)

javascript

16
推荐指数
2
解决办法
1579
查看次数

如何“取消引用”一个对象?

在 JavaScript 中,如何解引用函数返回的对象?

例如这个:

var tmp = getTextProperties();
font   = tmp.font;
size   = tmp.size;
color  = tmp.color;
bold   = tmp.bold;
italic = tmp.italic;
Run Code Online (Sandbox Code Playgroud)

PHP 具有 list() 构造,它执行类似的操作:

list($font, $size, $color, $bold, $italic) = getTextProperties();
Run Code Online (Sandbox Code Playgroud)

javascript php

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

如何获取相机预览的高度?

使用react-native-camera(RNCamera),当预览是窗口的全宽且完整预览可见时,我正在努力将相机预览的高度设置为正确。此问题假设设备始终处于纵向模式。

我的代码如下:

import React, { Component } from "react";
import { Dimensions, Button, View } from "react-native";
import { RNCamera } from "react-native-camera";

export default class CameraScreen extends Component {
  static navigationOptions = {
    header: null
  };
  render() {
    return (
      <View>
        <RNCamera
          ref={ref => {
            this.camera = ref;
          }}
          style={{
            width: Dimensions.get("window").width,
            height: 400 // <-- need to know what this value actually is
          }}
          type={RNCamera.Constants.Type.back}
        />
        <Button
          title="This button should appear directly below the camera preview" …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-native-camera

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