Inline onclick JavaScript variable(内联 onclick JavaScript 变量)
问题描述
我在这个 html 上面有一个 JavaScript 有没有办法在下面的代码中将它传递到 EditBanner(JS Variable Here) 中?
I have a JavaScript above this html is there any way to pass it inside EditBanner(JS Variable Here) in code below ?
//EditBanner to be changed to pass a Js variable.
<input id="EditBanner" type="button" value="Edit Image" onclick="EditBanner();"/>
推荐答案
有一个完整的实践说拥有内联函数/样式是个坏主意.考虑到您已经有按钮的 ID,请考虑
There's an entire practice that says it's a bad idea to have inline functions/styles. Taking into account you already have an ID for your button, consider
JS
var myvar=15;
function init(){
document.getElementById('EditBanner').onclick=function(){EditBanner(myvar);};
}
window.onload=init;
HTML
<input id="EditBanner" type="button" value="Edit Image" />
这篇关于内联 onclick JavaScript 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:内联 onclick JavaScript 变量
基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
