作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要评估一个保存为字符串的函数,然后在 JS 代码中使用它,场景如下:
第一步
<textarea id="function_text">function test(e){ alert(e.id); }</textarea>
第 2 步
var thatFunction = eval($("#function_text").val()); // returns undefined
步骤 3
thatFunction.call({id: 100});
有办法吗?
附言我知道所有安全注意事项,我只需要在第 3 步收到 100 个警报!
最佳答案
我要给你一个警告,不要这样做,但方法如下:
var thatFunction = Function('return ' + $("#function_text").val())();
thatFunction.call({id: 100});
关于javascript - 将字符串评估为可调用的 JS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17792271/
在不使用 css 或 table 的情况下帮助 php 或 html 中的 div 新手。 尝试使用具有以下行为的 div 执行此 4 x 列、2 x 行 // [.....adjustable..
我有这个部分: 我想要实现的是让左边的跨度,右边的填充,然后是中间的 HR,右边的跨度和价格,但我想让价格对齐向右,并使 HR 可调,因此它始终以价格结束并在第一个跨度之后开始。无论我如何尝试,我都无
我是一名优秀的程序员,十分优秀!