调用JSP中的Javascript函数
calling Javascript function in JSP
我正试图在JSP中调用一个函数并通过它激活警报
这就是我迄今为止所做的:
<html>
<head>
<script type="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
function myFunction( test )
{
alert( test );
}
</script>
<title>Success</title>
</head>
<body>
<c:set var="test" scope="request" value="${requestScope.userDetails }"></c:set>
<input type="button" id="sample_button" onclick="myFunction(${test.userName})" value="test">
</body>
</html>
我的代码出了什么问题?
您在script
元素中有一个meta
元素,在解析脚本块时会引发错误
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<script type="text/javascript">
function myFunction( test )
{
alert( test );
}
</script>
<title>Success</title>
</head>
<body>
<c:set var="test" scope="request" value="${requestScope.userDetails }"></c:set>
<input type="button" id="sample_button" onclick="myFunction(${test.userName})" value="test" />
</body>
</html>
除此之外,您可能还需要在调用函数中添加一个引号
<input type="button" id="sample_button" onclick="myFunction('${test.userName}')" value="test">
检查javascript错误&在浏览器中验证生成的HTML
相关文章:
- 从函数JavaScript返回不可变数组/对象
- 将对象传递给函数.JavaScript
- 如何定义const函数javascript(语法糖)
- 新的日期函数javascript
- TypeError:this.getAttribute不是一个函数-javascript
- 从函数javascript发送变量
- 扩展自容器函数Javascript
- 从内部函数javascript内部分配外部函数的对象
- 使用函数JavaScript中的函数
- 在这里使用回调函数(JavaScript)有什么好处吗
- 来自函数 Javascript 的 NaN 返回值 ||函数执行顺序
- 将“e”传递给一个新函数 - javascript
- 调用函数中的一个函数——Javascript
- 传递的变量不适用于我的函数-Javascript
- 如何将类方法设置为等于多个函数?-Javascript
- 显示php中的函数javascript
- 如何使用php代码创建函数Javascript弹出框
- 未调用的外部函数-javascript
- 如何在类中运行函数.Javascript
- 关闭mouseover上的一个函数——Javascript,jQuery