javascript 在警告框中传递字符串变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19239586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing string variable in alert box
提问by John
I have below script where im passing scriptlet variable to javascript function. But there is no alert box displaying.. Please let me what im missing here..
我有下面的脚本,其中我将 scriptlet 变量传递给 javascript 函数。但是没有显示警告框..请让我在这里缺少什么..
<script language="JavaScript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = "<%=res%>";
alert(Value);
document.Form.submit();
};
</script>
Thanks in advance
提前致谢
回答by The Hungry Dictator
try this....
试试这个....
<script type="text/javascript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = <%=res%>;
windows.alert(Value);
document.Form.submit();
};
</script>
回答by Aashray
What you need to use is <%= ... %>
. Try using this:
您需要使用的是<%= ... %>
. 尝试使用这个:
<script type="text/javascript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = <%=res%>;
alert(Value);
document.Form.submit();
};
</script>
回答by Vinoth Krishnan
@John Why you creating scriptlet tag inside javascript. Instead try using this,
@John 为什么要在 javascript 中创建 scriptlet 标签。而是尝试使用这个,
<%
String res = request.getParameter("Message");
%>
<script type="text/javaScript">
window.onload = function(){
var Value = "<%=res%>";
alert(Value);
document.Form.submit();
};
</script>
else try using jquery plugin for your purpose,
否则尝试使用 jquery 插件来达到您的目的,
<%
String res = request.getParameter("Message");
%>
<script type="text/javaScript">
$(document).ready(function() {
var Value = "<%=res%>";
alert(Value);
$('form#myForm').submit();
});
</script>