获得参考做脚本的父元素脚本、元素

2023-09-10 14:29:14 作者:小祖宗

我使用AJAX来返回一个响应,其中包括一个脚本。

I am using AJAX to return a response which includes a script.

通过该脚本,我怎么能确定的脚本运行父元素的​​ID没有通过的ID到服务器?有什么办法?

Through that script, how can I determine the ID of the parent element the script is running in without passing id's to the server? Is there a way?

感谢。

推荐答案

如果您分配一个ID为脚本(的将在古老的浏览器爆炸的),你可以试试:

If you assign an ID to the script (which will explode in ancient browsers), you can try:

var id = $("#idOfTheScript").parent()[0].id;