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 作为选择器选择拇指。你能帮忙吗?
<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检查数组项是否以“前缀”一词开头。
到目前为止,我已经做了这样的事情:
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)
出于某种原因,我不断收到未定义前缀的错误。请帮忙。
我正在尝试在 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 ×4
arrays ×1
if-statement ×1
input ×1
interface ×1
object ×1
onchange ×1
prefix ×1
range ×1
reactjs ×1
setstate ×1
state ×1
string ×1
typescript ×1
variables ×1