I need to remove script and after that, function as $('body').click(function (e) {
has not to work, because it is located in removed that script.
我需要删除脚本,之后,作为$('body')。单击(函数(e){无法工作,因为它位于删除该脚本。
i do:
$('script[src^="app/common/kendoGridExtendedHelper.js?1"]').remove();
buuuut after $('body').click(function (e) {
keeps working and i can see this script in browser by dev tools.
buuuut在$('body')之后。单击(function(e){继续工作,我可以通过开发工具在浏览器中看到这个脚本。
Help please
1 个解决方案
#1
0
It doesn't work like you're assuming. When the script runs and the click event handler is attached to 'body'
, it's in the DOM already, and nothing you do with the script tag will change that.
它不像你假设的那样有效。当脚本运行并且click事件处理程序附加到“body”时,它已经在DOM中,并且您对脚本标记所做的任何操作都不会改变它。
You'll have to remove the handler in your own script, just do:
您必须在自己的脚本中删除处理程序,只需执行以下操作:
$('body').off('click');
This can be messy, and break other functionalities, as every click handler is going to be removed from 'body'
. The ideal approach for this cases is to use namespaces. If you have control in that script you were trying to remove, attach the click handler with a namespace:
这可能是混乱的,并打破其他功能,因为每个点击处理程序将从“正文”中删除。这种情况的理想方法是使用名称空间。如果您在尝试删除的脚本中拥有控制权,请使用命名空间附加单击处理程序:
$('body').on('click.somenamespace', function () { ... });
And then in your script detach it using the same namespace:
然后在您的脚本中使用相同的命名空间分离它:
$('body').off('click.somenamespace');
#1
0
It doesn't work like you're assuming. When the script runs and the click event handler is attached to 'body'
, it's in the DOM already, and nothing you do with the script tag will change that.
它不像你假设的那样有效。当脚本运行并且click事件处理程序附加到“body”时,它已经在DOM中,并且您对脚本标记所做的任何操作都不会改变它。
You'll have to remove the handler in your own script, just do:
您必须在自己的脚本中删除处理程序,只需执行以下操作:
$('body').off('click');
This can be messy, and break other functionalities, as every click handler is going to be removed from 'body'
. The ideal approach for this cases is to use namespaces. If you have control in that script you were trying to remove, attach the click handler with a namespace:
这可能是混乱的,并打破其他功能,因为每个点击处理程序将从“正文”中删除。这种情况的理想方法是使用名称空间。如果您在尝试删除的脚本中拥有控制权,请使用命名空间附加单击处理程序:
$('body').on('click.somenamespace', function () { ... });
And then in your script detach it using the same namespace:
然后在您的脚本中使用相同的命名空间分离它:
$('body').off('click.somenamespace');