我正在阅读一个文本文件。然后在名为“$arrpg”的数组中将其拆分为 100 个单词,然后在我的 js 代码中将其加载到 js 变量中,var 无法正确获取数组值。如果您不介意,请查看我出于测试目的上传的链接(链接)
这里我的输入文本文件是“
A MUSIISTA EO GUERREIRO À noite, deitado, no escuro, não tenho forças para evitar o Concerto da virtuose muriçoca。Ela vem dali até aqui na velocidade do som。Procuro capturá-la com a mão, ela -- vivace -- ......................还有更多
"
我的js代码是
<script type="text/javascript" charset="UTF-8">
$(document).ready(function() {
var ind=0;
var tempv1;
var tempv2;
var pages=<?php echo json_encode((int)($page_num));?>;
var jsarr= <?php echo json_encode($arrpg); ?>;
var wmap=<?php
echo json_encode($word_map); ?>;
var myurl=<?php echo json_encode($my_link.'write_comment/'.$file_name.'/'.$total_word.'/');?>
$('.more').each(function() {
pages++;
$(this).html(jsarr[ind]);
tempv2= ' <a class="link2" href="'+myurl+wmap[0] + '">';
if(pages!==1)
{
tempv1='<span>.... <a href=""class="link1">Read more</a></span>';
tempv2='<br><br>'+tempv2+'Stop reading</a>';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
else
{
tempv2='<br><br>'+tempv2+'Please a feedback</a>';
$('div.link2').html(tempv2);
}
scroll();
});
$(".link1").click(function(){
ind++;
$('div.more').append(jsarr[ind]);
tempv2= '<a class="link2" href="'+myurl+wmap[ind] + '">';
if(ind<(pages-1) )
{
tempv1='<span>.... <a href=""class="link1">Read more</a></span>';
tempv2='<br><br>'+tempv2+'Stop reading</a>';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
else
{
tempv2='<br><br>'+tempv2+'Please a feedback</a>';
tempv1='';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
scroll();
return false;
});
});
function scroll(){
$('html, body').animate({
scrollTop: $("#ft").offset().top
}, 0);
}
</script>
在 jsarr 的此代码声明中无法正确获取值。看到链接你会意识到更多。请帮忙。
第一次编辑后
`<script type="text/javascript" charset="UTF-8">
$(document).ready(function() {
var ind=0;
var tempv1;
var tempv2;
var pages=5;
var jsarr= [" A MUSICISTA E O GUERREIRO\r\n"," a m"," agudo violino. Cubro a\\norelha, sinto calor, descubro a orelha, escuto a muri"," da habilidosa\\ninstrumentista. Na manh"," palmas de\\nminhas m"," morta, rubronegra\\n-- na plan"];
alert(jsarr);
var wmap=[30,60,90,120,150,175];
var myurl="http:\/\/leiame.patio.com.br\/read\/write_comment\/muricoca\/175\/"
$('.more').each(function() {
pages++;
$(this).html(jsarr[0]);
tempv2= ' <a class="link2" href="'+myurl+wmap[0] + '">';
if(pages!==1)
{
tempv1='<span>.... <a href=""class="link1">Read more</a></span>';
tempv2='<br><br>'+tempv2+'Stop reading</a>';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
else
{
tempv2='<br><br>'+tempv2+'Please a feedback</a>';
$('div.link2').html(tempv2);
}
scroll();
});
$(".link1").click(function(){
ind++;
$('div.more').append(jsarr[ind]);
tempv2= '<a class="link2" href="'+myurl+wmap[ind] + '">';
if(ind<(pages-1) )
{
tempv1='<span>.... <a href=""class="link1">Read more</a></span>';
tempv2='<br><br>'+tempv2+'Stop reading</a>';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
else
{
tempv2='<br><br>'+tempv2+'Please a feedback</a>';
tempv1='';
$('div.link1').html(tempv1);
$('div.link2').html(tempv2);
}
scroll();
return false;
});
});
function scroll(){
$('html, body').animate({
scrollTop: $("#ft").offset().top
}, 0);
}
</script>`