javascript - 未定义的 JavaScript 函数错误

标签 javascript function iframe

我制作了一个简单的 JavaScript 函数,该函数在单击按钮时执行 -

<asp:TextBox ID="TextBox3" runat="server" Width="98px"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Text="Button" OnClientClick="fn4();" />

<script  type="text/javascript">

function fn4() 
{

var search = document.getElementById('TextBox3').value;

<iframe src="http://fooBar.com/q=" + search + " width="250" height="400" scrolling="no" frameborder="0"></iframe>

}
</script>

因此,搜索项基于来自TextBox3的用户输入,但是当执行此操作时,会出现错误 -

Error: 'fn4' is undefined

我该如何解决这个问题?

最佳答案

加载页面时,您的浏览器中可能会出现解析器错误。因为 JavaScript 没有解析,所以函数没有定义。这是无效的 JavaScript:

function fn4() 
{

    var search = document.getElementById('TextBox3').value;

    <iframe src="http://fooBar.com/q=" + search + " width="250" height="400" scrolling="no" frameborder="0"></iframe>

}

其中混有 HTML,因此不会解析为 JavaScript。您到底想用该 iframe 做什么?

关于javascript - 未定义的 JavaScript 函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11011433/

相关文章:

javascript - 初学者 - 使用以下 While 循环时出现 "NaN"错误

javascript - 使用正则表达式验证 dxtextbox

javascript - 更改 JSON 对象

javascript - _.delay 函数缺少什么?

javascript - 如何将 iFrame 的部分 URL 更改为随机字符串?

javascript - 保护未指定的 Javascript 事件处理程序不被垃圾收集

c++ - 如何包装作为成员函数的 DLL 函数?

c++ - libzip : what is the first argument? 中的 zip_source_zip

javascript - 防止html页面打开新窗口

python - 应用引擎上的 Facebook 应用在 Canvas iframe 上显示为空白页面