将数组插入 location.href
我有一个程序将输入按钮放在表单上。当用户单击按钮时,onclick 属性使用 location.href 将其定向到链接。
elementButton_1.setAttribute("onclick", "self.location.href='http://google.com'; return false");
我正在尝试将链接存储在数组中。 如何将数组插入到位置调用中?
例子:
locationArray = new Array();
locationArray[0] = "http://google.com";
elementButton_1.setAttribute("onclick", "self.location.href=locationArray[0]; return false");
I have a program that places input buttons on a form. When a user clicks on the button the onclick attribute uses location.href to direct it to a link.
elementButton_1.setAttribute("onclick", "self.location.href='http://google.com'; return false");
I am trying to store the links in an array.
How can i insert an array into the location call?
Example:
locationArray = new Array();
locationArray[0] = "http://google.com";
elementButton_1.setAttribute("onclick", "self.location.href=locationArray[0]; return false");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要定义了
elementButton_1
,您发布的内容就可以工作。但是,更好的做法是:最好不要将可运行代码定义为字符串,以确保安全性和安全性。可维护性目的。
As long as
elementButton_1
is defined, what you posted will work. However, a much better practice is:It's better not to define runnable code as a string, for security & maintainability purposes.
我不完全确定我理解,但我认为你想要:
I'm not entirely sure I understand but I think you want: