小编Acd*_*cdn的帖子

错误:类型“{}”缺少类型中的以下属性

interface Person {
  name: string;
  surname: string;
}
let person1: Person = {};

person1.name = "name"
person1.surname = "surname"
Run Code Online (Sandbox Code Playgroud)

当我声明 person1 时,出现此错误:

Type '{}' is missing the following properties from type Person

javascript interface object typescript

12
推荐指数
2
解决办法
6万
查看次数

更改输入类型=“范围”拇指javascript的图像

当值发生变化时,我试图更改滑动范围的拇指图像。

问题是我不知道如何使用 javascript 作为选择器选择拇指。你能帮忙吗?

      <div class="slider-bar">
              <input type="range" id="myRange" min="0" max="10" value="0" />
        </div>

            input[type=range]::-webkit-slider-thumb {
                        -webkit-appearance: none;
                        border: none;
                        height: 50px;
                        width: 50px;
                        border-radius: 50%;
                        background:url(images/image.jpg) center no-repeat;
                        margin-top: -24px;
                        }
            input[type=range]:focus {
                        outline: none;
                        }
            input[type=range]::-moz-range-thumb {
                        border: none;
                        height: 50px;
                        width: 50px;
                        border-radius: 50%;
                        background:url(images/image.jpg) center no-repeat;
                        margin-top: -24px;}

var slider = document.getElementById("myRange");
    function xvalue () {
        var x = document.getElementById("myRange").value;
        console.log(x);
        if(x==1 && x==2 && x==3) {
            thumb.style.backgroundImage = "url('images/image1.jpg')";
        } else if (x==4 && x==5 …
Run Code Online (Sandbox Code Playgroud)

javascript input onchange range

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

检查字符串是否以前缀开头

我想用javascript检查数组项是否以“前缀”一词开头。

到目前为止,我已经做了这样的事情:

let array = ["prefix-word1", "prefix-word2"];

array.forEach(function(element) {
      if (element.lastIndexOf('prefix', 0) == 0) {
        console.log('prefix');
      }
    }
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我不断收到未定义前缀的错误。请帮忙。

javascript arrays string if-statement prefix

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

更新变量并立即使用它 React

我正在尝试在 api 调用后更新变量,但我将使用点击事件来解决这个问题。

如您所见,我打印的变量在第一次单击时使用旧状态,因为它尚未注册更改。在以下调用中,变量将打印新文本。

有没有办法在changeText函数中立即使用更新后的变量?

https://stackblitz.com/edit/react-36jqi3

export default function App() {
  const [text, setText] = useState('inital text');

  const changeText = () => {
    setText('new text');
    console.log(text);
  };

  return (
    <div>
      <button onClick={changeText}>Update variable</button>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

javascript variables state setstate reactjs

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