[英]How can i use this Javascript with jQuery in a INPUT TEXT?
I would like to know how can i use/transform this function in order to get work into a INPUT TEXT... 我想知道如何使用/转换此功能,以便将工作转化为输入文本...
Actually works if target is a DIV, but i would like use it into a INPUT TEXT... 如果目标是DIV,则实际上有效,但我想将其用于输入文本中...
The code i found and i want to use is: 我找到并想要使用的代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="js/jquery.js" type="text/javascript"></script>
<script language="JavaScript">
$(document).ready(function (){
textWrite("THIS'S A MESSAGE, I WOULD LIKE WRITE IT INTO A INPUT TYPE TEXT", '#write', 50);
});
function textList()
{
max = textList.arguments.length;
for (i = 0; i < max; i++)
this[i] = textList.arguments[i];
}
function textWrite(txt, selector, time)
{
$(selector).empty();
var x = 0; pos = 0;
var tl = new textList
(
txt
);
var l = tl[0].length;
textInterval(selector, tl, l, x, pos, time);
}
function textInterval(selector, tl, l, x, pos, time)
{
var interval =
setInterval(function() {
$(selector).html(tl[x].substring(0,pos));
if(pos++ == l)
clearInterval(interval);
}, time);
}
</script>
<title>Untitled Document</title>
</head>
<body>
<div id="write" /></div>
<input type="text" name="WriteHerePlease" id="WriteHerePlease" />
</body>
</html>
Thank in advance for all the help you can give me. 预先感谢您能给我的所有帮助。
So in case of input field you just need to set value
( val
method) instead of innerHTML
( html
method): 因此,在输入字段的情况下,您只需要设置
value
( val
方法)而不是innerHTML
( html
方法)即可:
function textWrite(txt, selector, time) {
$(selector).val('');
var x = 0;
var pos = 0;
var tl = new textList(txt);
var l = tl[0].length;
textInterval(selector, tl, l, x, pos, time);
}
function textInterval(selector, tl, l, x, pos, time) {
var interval = setInterval(function () {
$(selector).val(tl[x].substring(0, pos));
if (pos++ == l) clearInterval(interval);
}, time);
}
Demo: http://jsfiddle.net/epy2xrwL/ 演示: http : //jsfiddle.net/epy2xrwL/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.