Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 截断循环中文本的字符_Javascript_Html - Fatal编程技术网

Javascript 截断循环中文本的字符

Javascript 截断循环中文本的字符,javascript,html,Javascript,Html,我这里有点问题 我基本上是在一个div中循环项目,这样每个项目都有一个可以使用的键,这样当单击一个图标时,就会出现一个编辑模式,并填充所选项目的数据 这是可行的,但我想为span{{{$node->comment}}添加功能,这样,如果文本超过10个字符,它就会用“***”替换10个字符之后的所有内容。我试图通过添加element.innerHTML=getValue.substring(0,4)+'***'来实现这一点,但它不起作用,并且它放弃了使用键的功能 是否有办法替换文本字符并保留循环/

我这里有点问题

我基本上是在一个div中循环项目,这样每个项目都有一个可以使用的键,这样当单击一个图标时,就会出现一个编辑模式,并填充所选项目的数据

这是可行的,但我想为span
{{{$node->comment}}
添加功能,这样,如果文本超过10个字符,它就会用“***”替换10个字符之后的所有内容。我试图通过添加
element.innerHTML=getValue.substring(0,4)+'***'
来实现这一点,但它不起作用,并且它放弃了使用键的功能

是否有办法替换文本字符并保留循环/键功能

@foreach($nodes as $key => $node)  


        <div class="uk-width-1-1">
            <div class="uk-grid uk-grid-small">
                <div class="uk-width-2-10">
                {{$node->id}} - {{$node->desc}}
                </div>
                <div class="uk-width-2-10 testLoop">
                    <span>{{ $node->comment }}</span> 
                     <a href="#edit-modal{{ $key }}" data-uk-modal><span class="uk-icon-check"></span></a> 
                </div>
            </div>
        </div>

        <div id="edit-modal{{ $key }}" class="uk-modal"> 
            <div class="uk-modal-dialog">
                <div class="uk-width-1-1">
                    <div class="uk-grid uk-grid-small">
                        <div class="uk-width-2-10">
                        {{$node->id}} - {{$node->desc}}
                        </div>

                        <div class="uk-width-2-10 testLoop">
                            <span>{{ $node->comment }}</span> 
                        </div>
                    </div>
                </div>
            </div>
      </div>
@endforeach

function testLoop() {

var comment = document.getElementsByClassName('testLoop'),
    commentText = comment;

for (var index = 0; index < commentText.length; index++) {
    var element = commentText[index];
    var getValue = element.children[0].innerHTML;

    element.addEventListener('click',function(){
        console.log('click');
    })      
    }       
}
testLoop();
@foreach($nodes as$key=>$node)
{{$node->id}-{{$node->desc}
{{$node->comment}
{{$node->id}-{{$node->desc}
{{$node->comment}
@endforeach
函数testLoop(){
var comment=document.getElementsByClassName('testLoop'),
评论文本=评论;
对于(var index=0;index
对于10个字符,子字符串应为
(0,10)

let element=document.getElementById('text'))
element.innerText=element.innerText.substring(0,10)+'***'

长文本
对于十个字符,子字符串应为
(0,10)

let element=document.getElementById('text'))
element.innerText=element.innerText.substring(0,10)+'***'

Long text
我更喜欢CSS版本,现在就使用它。谢谢有一个版本的文本溢出可以让你指定字符,但它在Chrome上不起作用。我更喜欢CSS版本,现在就使用它。谢谢有一个版本的文本溢出允许您指定字符,但它不适用于Chrome。