Javascript 如何使用window.openonclick-reactjs
我想使用Javascript 如何使用window.openonclick-reactjs,javascript,reactjs,Javascript,Reactjs,我想使用窗口。打开,但收到以下错误消息: Uncaught Error: Expected onClick listener to be a function, instead got type string 我的代码: <img id='drftrgvlnbpewmcswmcs' style={{cursor:'pointer'}} onClick='window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=
窗口。打开,但收到以下错误消息:
Uncaught Error: Expected onClick listener to be a function, instead got type string
我的代码:
<img id='drftrgvlnbpewmcswmcs' style={{cursor:'pointer'}} onClick='window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup","toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30")' alt='' src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'/>
正如它所说的未捕获错误:预期onClick listener是一个函数,而不是获取类型string
它应该是一个函数。因此,您可以执行以下操作
openMyWindow = () => {
window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup","toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30")
}
像这样使用它
<img id='drftrgvlnbpewmcswmcs' style={{cursor:'pointer'}} onClick={this.openMyWindow} alt='' src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'/>
正如它所说的uncaughterror:期望onClick侦听器是一个函数,而不是得到类型string
它应该是一个函数。因此,您可以执行以下操作
openMyWindow = () => {
window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup","toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30")
}
像这样使用它
<img id='drftrgvlnbpewmcswmcs' style={{cursor:'pointer'}} onClick={this.openMyWindow} alt='' src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'/>
您需要用函数封装代码。例如:
<img
id='drftrgvlnbpewmcswmcs'
style={{ cursor: 'pointer' }}
onClick={() => {
window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup", "toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30")
}}
alt=''
src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'
/>
您需要用函数封装代码。例如:
<img
id='drftrgvlnbpewmcswmcs'
style={{ cursor: 'pointer' }}
onClick={() => {
window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup", "toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30")
}}
alt=''
src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'
/>
不能将计划字符串放在onClick prop中。你必须传递一个函数
例子
不能将计划字符串放在onClick prop中。你必须传递一个函数
例子
我希望代码对您有用
<img
id='drftrgvlnbpewmcswmcs'
style={{cursor:'pointer'}}
onClick={()=>{ window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup","toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30") }}
alt=''
src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'
/>
我希望代码对您有用
<img
id='drftrgvlnbpewmcswmcs'
style={{cursor:'pointer'}}
onClick={()=>{ window.open("http://trustseal.enamad.ir/Verify.aspx?id=15288&p=nbpdyncrwkynaqgwaqgw", "Popup","toolbar=no, location=no, statusbar=no, menubar=no, scrollbars=1, resizable=0, width=580, height=600, top=30") }}
alt=''
src='http://trustseal.enamad.ir/logo.aspx?id=15288&p=lznbfujyqesgukaqukaq'
/>