Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript onMouseOver React.js中的两个函数 render:function(){ 返回( document.getElementById(this.props.image.id).height=“80”,()=>document.getElementById(this.props.image.id).width=“80”} onMouseOut={()=>document.getElementById(this.props.image.id).height=“40”,()=>document.getElementById(this.props.image.id).width=“40”}/> ); }_Javascript_Reactjs - Fatal编程技术网

Javascript onMouseOver React.js中的两个函数 render:function(){ 返回( document.getElementById(this.props.image.id).height=“80”,()=>document.getElementById(this.props.image.id).width=“80”} onMouseOut={()=>document.getElementById(this.props.image.id).height=“40”,()=>document.getElementById(this.props.image.id).width=“40”}/> ); }

Javascript onMouseOver React.js中的两个函数 render:function(){ 返回( document.getElementById(this.props.image.id).height=“80”,()=>document.getElementById(this.props.image.id).width=“80”} onMouseOut={()=>document.getElementById(this.props.image.id).height=“40”,()=>document.getElementById(this.props.image.id).width=“40”}/> ); },javascript,reactjs,Javascript,Reactjs,我想在onMouseOver时更改图像大小,但它只更改了宽度。 如何在onMouseOver中使用两个函数。谢谢。简单一点。您可以定义一个新函数来立即调用它们 render: function() { return ( <td> <img src={this.props.image.path} width="40" height="40" id={this.props.image.id}

我想在onMouseOver时更改图像大小,但它只更改了宽度。
如何在onMouseOver中使用两个函数。谢谢。

简单一点。您可以定义一个新函数来立即调用它们

render: function() {

    return (
            <td>
              <img src={this.props.image.path} width="40" height="40" id={this.props.image.id}
              onMouseOver={()=>document.getElementById(this.props.image.id).height="80", ()=>document.getElementById(this.props.image.id).width="80"}
              onMouseOut={()=>document.getElementById(this.props.image.id).height="40", ()=>document.getElementById(this.props.image.id).width="40"}/>
            </td>
        );
    }
然后,用它替换onMouseOver的内容

function changeWidthAndHeight() {
  document.getElementById(this.props.image.id).height="80"
  document.getElementById(this.props.image.id).width="80"
}

简单一点。您可以定义一个新函数来立即调用它们

render: function() {

    return (
            <td>
              <img src={this.props.image.path} width="40" height="40" id={this.props.image.id}
              onMouseOver={()=>document.getElementById(this.props.image.id).height="80", ()=>document.getElementById(this.props.image.id).width="80"}
              onMouseOut={()=>document.getElementById(this.props.image.id).height="40", ()=>document.getElementById(this.props.image.id).width="40"}/>
            </td>
        );
    }
然后,用它替换onMouseOver的内容

function changeWidthAndHeight() {
  document.getElementById(this.props.image.id).height="80"
  document.getElementById(this.props.image.id).width="80"
}

将它们合并为一个函数

onMouseOver={changeWidthAndHeight}

或者您可以将这些样式设置为变量,然后使用
onMouseOver

将它们合并到一个函数中进行更新

onMouseOver={changeWidthAndHeight}
或者,您可以将这些样式设置为变量,然后使用
onMouseOver

更新该样式,如下所示:

onMouseOver={()=> {
  let obj = document.getElementById(this.props.image.id);
  obj.height="80"; 
  obj.width="80";
}}
但最好使用函数

onMouseOver={() => {
    document.getElementById(this.props.image.id).height = "80";
    document.getElementById(this.props.image.id).width = "80";
    }
}
像这样使用它:

onMouseOver={()=> {
  let obj = document.getElementById(this.props.image.id);
  obj.height="80"; 
  obj.width="80";
}}
但最好使用函数

onMouseOver={() => {
    document.getElementById(this.props.image.id).height = "80";
    document.getElementById(this.props.image.id).width = "80";
    }
}

这当然是真的,但在箭头函数中加入大量逻辑不是一个好习惯。是的,但我遵循他的想法/逻辑。他必须先让它工作起来,然后再尝试重构或改进。这当然是真的,但在arrow函数中加入大量逻辑不是一个好习惯。是的,但我遵循他的想法/逻辑。他必须首先让它工作,然后他可以尝试重构或改进。你应该按照ES6标准使用箭头功能。我将把选择留给问题。你应该按照ES6标准使用箭头功能。我将把选择留给问题删除
HTML
标记,因为它与删除无关
HTML
标记,因为它与之无关