简体   繁体   English

使用jQuery获取其内容时,无法在div标签中的p个元素之间插入空格

[英]unable to insert space between p elements in a div tag when fetching its content with jQuery

Summary : 总结:

I am running the following syntax of jQuery : 我正在运行jQuery的以下语法:

var value = $('#displayContent').text();    

to count the words, but before I want to use the RegExp in value to add the last word and first word of each sentence together eg 计算单词,但是在我想使用RegExp value将每个句子的最后一个单词和第一个单词加在一起之前,例如

so if I had 3 lines the first line ending word is joined with the second line first word and pulls that as one word. 因此,如果我有3行,则将第一行结束词与第二行第一个词连接起来,并将其作为一个词拉出。

each line is in its own <p> tag Is there any way of running the above var to add a space to each p tag? 每行都在其自己的<p>标记中有运行上述var的方法来为每个p标记添加空间吗?

Any immediate help will be highly appreciable. 任何即时帮助将非常可贵。

code I am running is 我正在运行的代码是

 var _wordCount = function () {



    var value = $('#displayContent').text();


    if (value.length == 0) {
        $('#show_word_count').html(0);

        return;
    }


    $('#show_word_count').html(wordCount);

};

$(document).ready(function () {

    $('#displayContent').change(_wordCount);
    $('#displayContent').keydown(_wordCount);
    $('#displayContent').keypress(_wordCount);
    $('#displayContent').keyup(_wordCount);
    $('#displayContent').blur(_wordCount);


});

so the value keeps pulling the combined words 所以值不断拉动组合词

Sounds like you have a problem with linebreaks. 听起来您的换行符有问题。 If you had three sentences, if the last word and then the first word and being combined as one, the problem is you need to handle the linebreak between them. 如果您有三个句子,如果最后一个单词然后是第一个单词并被组合为一个,则问题是您需要处理它们之间的换行符。

As Rohit asked, I'd recommend posting code or just troubleshooting linebreaks ( \\n or \\r\\n ) to determine the problem. 如Rohit所问,我建议您发布代码或仅对换行符( \\ n\\ r \\ n )进行故障排除,以确定问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM