Javascript 表单选择 Selectedindex
遇到以下问题 - 未按预期工作,也出现 JS 文档错误。
Having problems with the following - Not working as expected, getting JS doc errors as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这个小提琴: http://jsfiddle.net/maniator/egjF4/6/
并更改if 行:
您需要
==
来检查值UPDATE
根据下面的评论,这里是同一件事的 jQuery:
try this fiddle: http://jsfiddle.net/maniator/egjF4/6/
and change the if line to:
you need the
==
to check valuesUPDATE
Based on your comments below here is the jQuery for the same thing:
你也可以这样做,http://jsfiddle.net/edelman/egjF4/10/
这样,您就可以缓存表单,以备以后引用它,从而防止另一个元素查找并加快代码速度。
you could also do this, http://jsfiddle.net/edelman/egjF4/10/
this way you're caching the form in case you want to reference it later, preventing another element lookup and speeding up your code.
我相信 jsfiddle 运行在它自己的小保护性 XPC 气泡中,因此 showhidebtime 不会被视为通过内联 javascript 调用定义。最佳实践是始终在 javascript 文件中添加事件,而不是与元素内联。
此外,您还需要更改表单以显示
name="myform"
才能使document.myform
正常工作。试试这个小提琴: http://jsfiddle.net/garreh/qb6fw/
I believe jsfiddle runs in it's own little protective XPC bubble, so showhidebtime will not be seen as defined via an inline javascript call. Best practice is to always add events in the javascript file, not inline with the elements.
Also you need to change your form to show
name="myform"
in order fordocument.myform
to work.Try this fiddle: http://jsfiddle.net/garreh/qb6fw/