如何将我的选择框值发送到 javascript
我有由 javascript 生成的随机数量的选择框,全部包含相同的选项。现在我希望有一个“主选择框”,它可以为每个选择框设置值。
目前我有
在 javascript 中,我已经找到了每个每个选择框和我已经知道如何设置值,但该值没有发送到 JavaScript。
在每次尝试中,我都将 getElementById(changeKlas)
设为 null。如何解决这个问题,以便我可以获取给定选择中所选文本框的文本和值?
I have a random amount of select boxes generated by javascript, all containing the same options. Now I wish to have a "master-selectbox" which sets the value for each and every one of them.
Currently I have <select id="changeKlas" onChange="javascript:changeClass(this.parentNode, getElementById(changeKlas))">
At the javascript I've gotten as far as to find each and every select box and I already know how to set the value but the value is not being send to javascript.
On each attempt I have made the getElementById(changeKlas)
is null. How can I fix this so I can get the text and value of the selected textbox in the given select?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个。
在 JavaScript 中,这将转换为
document.getElementById(changeKlas)
Try this.
And in your JavaScript, this will be transformed to
document.getElementById(changeKlas)
您需要引用 id:
[...], document.getElementById('changeKlas')
-- 注意单引号,双引号需要转义,因为外部来自onChange
。另外,请注意getElementById
属于document
You need to quote the id:
[...], document.getElementById('changeKlas')
-- notice the single quote, double quote needs to be escaped because of the outer one fromonChange
. Also, notice thatgetElementById
belongs todocument
// 发生变化时,它将提醒 SELECTED VALUE
// On change It will alert the SELECTED VALUE