如何限制元素及其子元素的 DOM 交互?
我正在为 PHP MVC 站点构建模块化框架。我正在使用 jQuery。我有一个 registerModule('module_name')
方法,调用该方法时会创建具有此名称的模块对象的实例。这些模块对象是返回包含在各个脚本文件中的对象的函数。
test_module.js 示例:
core.modoules.test_module = function(sandbox){
return{
init : function(){
}
};
};
在 registerModule()
方法中,我正在处理继承和初始化。在初始化时,我想检查 DOM 中是否有与此模块匹配的元素。对于此示例,我们将查找 id 为 test_module
的 div
,并且我希望将 test_module
对象内的任何 DOM 交互限制为在该 DOM 范围内。我目前正在使用 jQuery 的选择器,但感觉我可能需要编写自己的 DOM 包装器或其他东西。对此有什么想法吗?
I am building a modular framework for a PHP MVC site. I am using jQuery. I have a registerModule('module_name')
method that when called creates an instance of a module object with this name. These module objects are functions that return an object they are contained within individual script files.
Example of test_module.js:
core.modoules.test_module = function(sandbox){
return{
init : function(){
}
};
};
Within the registerModule()
method I am handling inheritance and initialization. On initialization, I would like to check the DOM for an element matching this module. For this example, we'd look for a div
with id test_module
and I would like to limit any DOM interaction within the test_module
object to be within that DOM scope. I currently am using jQuery's selectors but have the feeling I may need to write my own DOM wrapper or something. Any ideas on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$() 采用第二个参数,它限制了搜索范围
,这实际上与
$() takes a 2nd parameter which limits the search scope
which is really the same as