本文介绍了内嵌onclick JavaScript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<$ c $我有一个超过此html的JavaScript有没有办法在EditBanner(JS Variable Here) c> // EditBanner被改为传递一个Js变量。
< input id =EditBannertype =buttonvalue =Edit Imageonclick =EditBanner();/>
解决方案
具有内联函数/样式。
考虑到您的按钮已经有了一个ID,请考虑
JS
var myvar = 15;
函数init(){
document.getElementById('EditBanner')。onclick = function(){EditBanner(myvar);};
}
window.onload = init;
HTML
< input id =EditBannertype =buttonvalue =Edit Image/>
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();"/>
解决方案
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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!