简体   繁体   English

element.innerHTML无法调用我的javascript函数

[英]element.innerHTML can't call my javascript Function

I am so new to web development and I am encountering this problem. 我对Web开发非常陌生,并且遇到了这个问题。 I tried googling this but the problems that I saw is not related to mine. 我尝试使用谷歌搜索,但发现的问题与我无关。

I have a jsp file that contains only this code: 我有一个仅包含以下代码的jsp文件:

<script>
displaymessage();
</script>

and in my js file: I have this. 并在我的js文件中:我有这个。

$('ajax_content').innerHTML = resp.responseText;

where in the resp.responseText is equivalent to a string that represents the jsp file. resp.responseText中的等效于代表jsp文件的字符串。

The function inside the jsp file is existing in the compiled HTML page but the function is not called. jsp文件中的函数已存在于已编译的HTML页面中,但未调用该函数。

The function's purpose is just to display a message. 该功能的目的只是显示一条消息。 Could anybody help me? 有人可以帮我吗?

Inserting a script via innerHTML does NOT run that script. 通过innerHTML插入脚本不会运行该脚本。

Instead, you should remove those script tags and just run the AJAX response through eval . 相反,您应该删除这些script标记,然后通过eval运行AJAX响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM