表单或 select 的 onload() 函数是什么?
我试图在 JavaScript 中找到一个每次创建
我想要这样的东西:
<body onload="jsFunction();">
更准确地说,我需要做一个
我在服务器端使用JSP
I'm trying to find a function in JavaScript that is called everytime when a <form>
or <select>
is created. Does anyone have a idea?
I want something like:
<body onload="jsFunction();">
More exactly, I need to make a <select> that will be included in many pages, and I want everytime this is loaded, to select one of it's values based on a request variable. So the function that will make the selection must called from this included script and must be included in this script.
I'm using JSP on the server side
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这毫无意义。只需根据请求参数以编程方式设置整个
selected
属性即可。这是一个示例:或者如果您将其放在集合中:
对于普通输入也是如此:
(
fn:escapeXml()
是为了防止 XSS 攻击)This makes no sense. Just set the whole
selected
attribute programmatically based on the request parameter. Here's an example:or if you have it in a collection:
The same is true for normal inputs:
(the
fn:escapeXml()
is there to prevent XSS attacks)您可以尝试在默认情况下要选择的选项中使用“selected”属性(如此处的建议)。如果您更喜欢 javascript,则需要使用 jquery 之类的工具来选择(或填充并选择)您的标签。
供参考:
You could try the "selected" attribute in the option you want to select by default (like suggested here). If you prefer javascript, you'll need to use something like jquery to select select (or populate and select) your tag.
For reference: