Javascript:用字符串替换 onChange 事件
我目前正在 sharepoint 2007 的范围内工作,并且有一些代码可以将下拉列表变成组合框。我所拥有的工作得很好,但是此代码是供业务分析师和内容创建者使用的,因此它必须尽可能简单。所以我将它压缩成一个函数,除了 onChange 事件之外,一切都进展顺利。
我已设法提取原始的 onChange 事件,但由于我的下拉列表,我必须替换参数。因此,我将其转换为字符串,替换参数,然后需要将其重新转换为函数:
var onChangeFunction = "function (){alert("your function has been called")}"
//The function 'attachEvent' is not common javascript. It is a custom function
//that works for my combobox.
combobox.attachEvent("onChange",(function)onChangeFunction);
这可能吗?
I am currently working within the confines of sharepoint 2007 and have some code that turns a dropdownlist into a combobox. What i have works perfectly fine, however this code is meant to be used by business analysts and content creators so it has to be as simple as possible. So i am condensing it into a function and all has gone swimmingly except for the onChange event.
I have managed to extract the original onChange event, though due to my dropdownlist i have to replace a parameter. So i convert it to a string, replace the parameter and need to reconvert it to a function a la:
var onChangeFunction = "function (){alert("your function has been called")}"
//The function 'attachEvent' is not common javascript. It is a custom function
//that works for my combobox.
combobox.attachEvent("onChange",(function)onChangeFunction);
Is that even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
new Function
,但我认为您正处于滑坡状态。You can use
new Function
but I think you are on a slippery slope playing with this.