输出所有字符并识别 js 函数的结尾
output all characters and recognize end of js-function
我已经整理了下面提到的脚本。它不会输出最后一个源的最后一个字符。我不太关心 js,这就是我问你的原因。谁能给我一个线索?
function jtype(source, step){
var str = source, i = 0, isTag, text, all = "", ii = 0, totallength = 0;
for(ii = 1; ii < step; ii++){
all = all + $("#source-" + ii).val();
}
(function type() {
text = str.slice(0, ++i);
if (text === str) return;
$(".steps").html(all + text);
var char = text.slice(-1);
if( char === '<' ) isTag = true;
if( char === '>' ) isTag = false;
if (isTag) return type();
setTimeout(type, 20);
}());
}
这是一个示例数据源:
<input type="hidden" class="sources" id="source-1" value="Gesetzliche Zinsen gebühren kraft Gesetzes. ">
<input type="hidden" class="sources" id="source-2" value="Der gesetzliche Zinssatz beträgt nach <a href="#" onclick="dofadein('#norm330')">§ 1000 Abs 1 ABGB</a> 4 Prozentpunkte pro Jahr. ">
<input type="hidden" class="sources" id="source-3" value="Gesetzliche Zinsen sind insb die sog Verzugszinsen nach <a href="#" onclick="dofadein('#norm430')">§ 1333 ABGB</a>.">
在此示例中,它不会输出#source-3 末尾的点。
当我在函数 jtype() 中发出警报(源)时,点不会丢失。
我想知道的另一件事是。我如何确定输出的结尾。我的意思是:如何确定循环是否完成以及最后一个字符是否已输出?
非常感谢您的帮助,请原谅我的英语不好。
问题似乎是,当 text === str
你 return 在 更新元素之前,最后一个字符永远不会被插入
变化:
if (text === str) return;
$(".steps").html(all + text);
收件人:
// update element before ending
$(".steps").html(all + text);
if (text === str) return;
DEMO
我已经整理了下面提到的脚本。它不会输出最后一个源的最后一个字符。我不太关心 js,这就是我问你的原因。谁能给我一个线索?
function jtype(source, step){
var str = source, i = 0, isTag, text, all = "", ii = 0, totallength = 0;
for(ii = 1; ii < step; ii++){
all = all + $("#source-" + ii).val();
}
(function type() {
text = str.slice(0, ++i);
if (text === str) return;
$(".steps").html(all + text);
var char = text.slice(-1);
if( char === '<' ) isTag = true;
if( char === '>' ) isTag = false;
if (isTag) return type();
setTimeout(type, 20);
}());
}
这是一个示例数据源:
<input type="hidden" class="sources" id="source-1" value="Gesetzliche Zinsen gebühren kraft Gesetzes. ">
<input type="hidden" class="sources" id="source-2" value="Der gesetzliche Zinssatz beträgt nach <a href="#" onclick="dofadein('#norm330')">§ 1000 Abs 1 ABGB</a> 4 Prozentpunkte pro Jahr. ">
<input type="hidden" class="sources" id="source-3" value="Gesetzliche Zinsen sind insb die sog Verzugszinsen nach <a href="#" onclick="dofadein('#norm430')">§ 1333 ABGB</a>.">
在此示例中,它不会输出#source-3 末尾的点。 当我在函数 jtype() 中发出警报(源)时,点不会丢失。
我想知道的另一件事是。我如何确定输出的结尾。我的意思是:如何确定循环是否完成以及最后一个字符是否已输出?
非常感谢您的帮助,请原谅我的英语不好。
问题似乎是,当 text === str
你 return 在 更新元素之前,最后一个字符永远不会被插入
变化:
if (text === str) return;
$(".steps").html(all + text);
收件人:
// update element before ending
$(".steps").html(all + text);
if (text === str) return;