jQuery执行字符串作为函数 [英] jQuery execute string as function
本文介绍了jQuery执行字符串作为函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从服务器端JS向客户端js传递jQuery命令(以字符串的形式)。这允许我从服务器端修改客户端DOM的东西。
I want to pass in a jQuery command (in the form of a string) from server-side JS to client-side js. This allows me to modify client-side DOM stuff from the server-side.
功能:
$("textArea").attr("disabled","true");
我想做什么:
$['$("textArea").attr("disabled","true")']();
引发错误。想法?
推荐答案
您可以在客户端使用eval-function:
You could use the eval-function on the client-side:
这将立即执行你的javascript:
This will execute your javascript immediately:
eval('$("textArea").attr("disabled","true")');
但是,正如评论中所说的那样,要小心你所做的,因为这是一种非常粗暴的方法。
But, as said in the comments, be careful with what you do as this is a very crude method.
另外,就安全性而言,你并没有真正获得任何东西,因为仍然可以打开开发工具并删除已禁用的属性
Also, in terms of security, you don't really gain anything, because one could still open the dev-tools and remove the disabled attribute
这篇关于jQuery执行字符串作为函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文