如何将变量从HTML传递到Java?
我想把一个变量从HTML传递到Java。为此,我编写了以下代码:如何将变量从HTML传递到Java?,java,html,Java,Html,我想把一个变量从HTML传递到Java。为此,我编写了以下代码: <!doctype html> <html> <title>How to create a typewriter or typing effect with jQuery</title> <div id="example1">fsdfsdfojsdlk sdfj lskdhfk sdf </div> <style>
<!doctype html>
<html>
<title>How to create a typewriter or typing effect with jQuery</title>
<div id="example1">fsdfsdfojsdlk sdfj lskdhfk sdf </div>
<style>
body{
background: transparent;
color: #ec5a62;
}
#container{
font-size: 7em;
}
</style>
</head>
<body>
<div id="container"></div>
<!--
We use Google's CDN to serve the jQuery js libs.
To speed up the page load we put these scripts at the bottom of the page
-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script>
//define text
var text = ("document.getElementById("example1")");
//text is split up to letters
$.each(text.split(''), function(i, letter){
//we add 100*i ms delay to each letter
setTimeout(function(){
//we add the letter to the container
$('#container').html($('#container').html() + letter);
}, 30*i);
});
</script>
</body>
</html>
如何使用jQuery创建打字机或打字效果
FSDFSFOJSDLK sdfj lskdhfk sdf
身体{
背景:透明;
颜色:#ec5a62;
}
#容器{
字号:7em;
}
//定义文本
var text=(“document.getElementById(“example1”)”);
//文本被分成几个字母
$.each(text.split(“”),函数(i,字母){
//我们在每封信上加上100*i毫秒的延迟
setTimeout(函数(){
//我们把信放进容器里
$('#container').html($('#container').html()+字母);
},30*i);
});
但它不起作用。我怎样才能做到这一点
请帮帮我
我使用的是var text=(“document.getElementById(“example1”)”)强>
但它不起作用。要获取值,请使用var x=document.getElementById(“example1”).value 您的代码应该如下所示:
var text=document.getElementById("example1").value;
//text is split up to letters
$.each(text.split(''), function(i, letter){
//we add 100*i ms delay to each letter
setTimeout(function(){
//we add the letter to the container
$('#container').html($('#container').html() + letter);
}, 30*i);
});
学习使用jsp/jsf和servlets在这里会很有用。您的问题并不清楚:如果您的代码(html文档)在web浏览器中呈现,那么代码将在客户端执行。没有与任何只能位于服务器端的java代码的连接,并且您的代码不尝试发送任何东西……要将变量从HTML页面传递到java servlet,您需要发送ajax请求。也许您想将变量传递给Javascript代码?Javascript不等于Java!