gpt4 book ai didi

javascript - 我如何在输入文本中使用此 Javascript 和 jQuery?

转载 作者:行者123 更新时间:2023-11-28 00:26:19 25 4
gpt4 key购买 nike

我想知道如何使用/转换此函数以便将工作转换为输入文本...

如果目标是 DIV,则实际上有效,但我想将其用于输入文本...

我找到并想要使用的代码是:

<!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>

预先感谢您为我提供的所有帮助。

最佳答案

因此,在输入字段的情况下,您只需设置 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);
}

演示: http://jsfiddle.net/epy2xrwL/

关于javascript - 我如何在输入文本中使用此 Javascript 和 jQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29461096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com