字符串 - 我想使用jquery截断带省略号的文本或行? [英] String - I want to truncate a text or line with ellipsis using jquery?

查看:54
本文介绍了字符串 - 我想使用jquery截断带省略号的文本或行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用html页面在jquery中加载json数据。我需要Paragraph字是短的。例如维基百科搜索数据........



How to load json data in jquery using html page. i need Paragraph word is short . for example Wikipedia search datas ........

If i click the link Redirect to another page Paragraph full details are display. i sucessfully bind and redirect to another page.The html page for example Index.html and Newsdetails.html I need below example
My Output is:

Business Deals

Daimler India Commercial Vehicles (DICV) in association with Espirit Trucking has inaugurated a new BharatBenz dealership for its commercial vehicle brands in National Capital Region (NCR), Ghaziabad. It will cater BharatBenz trucks and buses as well as to Mercedes-Benz luxury buses. The company said in a statement, the opening of this new dealership which is owned and run by Espirit Trucking is an example of how DICV's dealer network continues to proliferate deeper into domestic market regions including tier II and tier III cities. Speaking at the inauguration of the new dealership, Sominder Singh, DICV's Vice President responsible for Domestic Sales, Product Management & Network said "We want to get even closer to our customers - in line with our continuous growth we are further expanding our sales and service network. Espirit Trucking is an experienced partner who will provide excellent sales and services to our customers from this new venture in Ghaziabad." Vivek Avasthi, Director, Espirit Trucking said, "Ghaziabad is the perfect location for this new full-fledged commercial vehicle dealership. Our investment here reflects our belief into the enormous growth opportunities for commercial vehicles in one of India's most vibrant regions, with the BharatBenz and Mercedes-Benz brands giving us the right products to be successful." The dealership will provide a host of value-added services such as cashless zero-depreciation insurance, full maintenance contracts, extended warranty, 24x7 roadside assistance, vehicle tracking systems, driver training, and on-site service.  



我想输出:


I Want to Output of:

<pre lang="C#">Business Deals

Daimler India Commercial Vehicles (DICV) in association with Espirit Trucking has inaugurated a new BharatBenz dealership for its commercial vehicle brands in National Capital Region (NCR), Ghaziabad. It will cater BharatBenz trucks and buses as well as to Mercedes-Benz luxury buses. The company said in a statement...........



请帮助我。 ...



我的尝试:



Index.html脚本:

< script type =text / javascript>



$(document).ready(function(){< br $> b $ b调试器;

// var id = 0;

$ .getJSON('http:// localhost:33804 / NewsRestService.svc / NewsById / 0',函数(数据){

var out =;

var i;

for(i = 0; i< ; data.NewsByIdResult.length; i ++){



var Encode = data.NewsByIdResult [i] .SourceVersion;

var Decode = $ ('


Please Help me....

What I have tried:

Index.html script:
<script type="text/javascript">

$(document).ready(function () {
debugger;
//var id = 0;
$.getJSON('http://localhost:33804/NewsRestService.svc/NewsById/0', function (data) {
var out = "";
var i;
for (i = 0; i < data.NewsByIdResult.length; i++) {

var Encode = data.NewsByIdResult[i].SourceVersion;
var Decode = $('

')。html(Encode).text();

var SourceVersionHtml = RemoveHTMLTags(Decode);



out + ='
').html(Encode).text();
var SourceVersionHtml = RemoveHTMLTags(Decode);

out += '
'

+'
'
+ '
'

+'

'+ data.NewsByIdResult [i] .NewsTopic +'

'

+'

'+ SourceVersionHtml +'

'
+ '

' + data.NewsByIdResult[i].NewsTopic + '

'
+ '

' + SourceVersionHtml + '

'

}

document.getElementById(newshref)。innerHTML = out;

});

});



函数RemoveHTMLTags(内容){

var regX = /(<([^>] +)>)/ ig;

var html = content;

var substring = html.replace (regX,);

返回子字符串;

}

< / script>



NewsDetails.Html脚本:



< script type =text / javascript>

函数GetParameterValues( param){

调试器

var url = window.location.href.slice(window.location.href.indexOf('?')+ 1).split(' &');

for(var i = 0; i< url.length; i ++){

var urlparam = url [i] .split('= ');

if(urlparam [0] == param){

return urlparam [1];

}

}

} $ / $
$(文件).ready(function(){

调试器

var newsid = GetParameterValues('newsid');

var url =http:// localhost:33804 / NewsRestService.svc / NewsById /+ newsid;

var out =;

$ .getJSON(url,function(data){

if(data.NewsByIdResult.length> 0){



var Encode = data.NewsByIdResult [0] .SourceVersion;

var Decode = $('

'
}
document.getElementById("newshref").innerHTML = out;
});
});

function RemoveHTMLTags(content) {
var regX = /(<([^>]+)>)/ig;
var html = content;
var substring = html.replace(regX, "");
return substring;
}
</script>

NewsDetails.Html Script:

<script type="text/javascript">
function GetParameterValues(param) {
debugger
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return urlparam[1];
}
}
}
$(document).ready(function () {
debugger
var newsid = GetParameterValues('newsid');
var url = "http://localhost:33804/NewsRestService.svc/NewsById/" + newsid;
var out = "";
$.getJSON(url, function (data) {
if (data.NewsByIdResult.length > 0) {

var Encode = data.NewsByIdResult[0].SourceVersion;
var Decode = $('

') .html(Encode).text();

var SourceVersionHtml = RemoveHTMLTags(Decode);



out + ='
').html(Encode).text();
var SourceVersionHtml = RemoveHTMLTags(Decode);

out += '
'

+'
'
+ '
'

+'

'+ data .NewsByIdResult [0] .NewsTopic +'

'

+'

'+ SourceVersionHtml +'

'
+ '

' + data.NewsByIdResult[0].NewsTopic + '

'
+ '

' + SourceVersionHtml + '

';

}



document.getElementById(newsget)。innerHTML = out;



});

});



函数RemoveHTMLTags(内容){

var regX = /(<([^ >] +)>)/ ig;

var html = content;

var substring = html.replace(regX, );

返回子字符串;

}

< / script>

';
}

document.getElementById("newsget").innerHTML = out;

});
});

function RemoveHTMLTags(content) {
var regX = /(<([^>]+)>)/ig;
var html = content;
var substring = html.replace(regX, "");
return substring;
}
</script>

推荐答案

(document).ready(function(){

debugger;

// var id = 0;
(document).ready(function () {
debugger;
//var id = 0;


.getJSON('http:// localhost:33804 / NewsRestService.svc / NewsById / 0',function(data){

var out =;

var i;

for(i = 0;我< data.NewsByIdResult.length; i ++){



var Encode = data.NewsByIdResult [i] .SourceVersion;

var Decode =
.getJSON('http://localhost:33804/NewsRestService.svc/NewsById/0', function (data) {
var out = "";
var i;
for (i = 0; i < data.NewsByIdResult.length; i++) {

var Encode = data.NewsByIdResult[i].SourceVersion;
var Decode =


('
')。html(Encode).text();

var SourceVersionHtml = RemoveHTMLTags(Decode);



out + ='
').html(Encode).text();
var SourceVersionHtml = RemoveHTMLTags(Decode);

out += '
'

+'
'
+ '
'

+'

'+ data.NewsByIdResult [i] .NewsTopic +'

'

+'

'+ SourceVersionHtml +'

'
+ '

' + data.NewsByIdResult[i].NewsTopic + '

'
+ '

' + SourceVersionHtml + '

'

}

document.getElementById (newshref)。innerHTML = out;

});

});



函数RemoveHTMLTags(内容){

var regX = /(<([^>] +)>)/ ig;

var html = content;

var substring = html.replace (regX,);

返回子字符串;

}

< / script>



NewsDetails.Html脚本:



< script type =text / javascript>

函数GetParameterValues( param){

调试器

var url = window.location.href.slice(window.location.href.indexOf('?')+ 1).split(' &');

for(var i = 0; i< url.length; i ++){

var urlparam = url [i] .split('= ');

if(urlparam [0] == param){

return urlparam [1];

}

}

}

'
}
document.getElementById("newshref").innerHTML = out;
});
});

function RemoveHTMLTags(content) {
var regX = /(<([^>]+)>)/ig;
var html = content;
var substring = html.replace(regX, "");
return substring;
}
</script>

NewsDetails.Html Script:

<script type="text/javascript">
function GetParameterValues(param) {
debugger
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return urlparam[1];
}
}
}


这篇关于字符串 - 我想使用jquery截断带省略号的文本或行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆