admin管理员组文章数量:1300185
I know this is an easy one, but I can't find exactly what I am looking for. I was wondering if it is possible to pass an array into a method as a parameter, but through HTML. If it is possible I think it would be something like this:
<img src="img.png" alt="picture" onclick="thisMethod1(['Facebook','Twitter'])"/>
The javascript would look something like this:
function thisMethod1(socialArray)
{
//use this array
}
Is this correct?
The reason I am asking is because there is an error in my code and I am trying to find it.
I know this is an easy one, but I can't find exactly what I am looking for. I was wondering if it is possible to pass an array into a method as a parameter, but through HTML. If it is possible I think it would be something like this:
<img src="img.png" alt="picture" onclick="thisMethod1(['Facebook','Twitter'])"/>
The javascript would look something like this:
function thisMethod1(socialArray)
{
//use this array
}
Is this correct?
The reason I am asking is because there is an error in my code and I am trying to find it.
- Post the real code and someone might find the problem. I suspect this question will get downvoted and maybe put on hold as it stands. – user2625787 Commented Aug 1, 2013 at 0:30
- What error are you getting? – Mike Brant Commented Aug 1, 2013 at 0:32
2 Answers
Reset to default 5Yes it should work, as this demonstrates:
<script>
function thisMethod1(socialArray)
{
alert(socialArray);
}
</script>
<img src="img.png" alt="picture" onclick="thisMethod1(['Facebook','Twitter'])"/>
If the image is inside a link, then clicking it might cause the link to submit, so that may be causing you to think there's an error in your code.
Yes, though best practice says not to use inline code (in the tag).
本文标签: Pass array in HTML method parameters javascriptStack Overflow
版权声明:本文标题:Pass array in HTML method parameters javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741652342a2390554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论