在字符后从输出中删除文本

时间:2015-05-28 13:06:11

标签: jquery

使用此功能处理表格时:

*$("tablelist div.panel",html).each(function( index ) {/*loop-start*/
    var job = {};/*init*/
    job.title = ($(this).text());
});/*loop-end*/*

我得到了结果:

文字1-Text2-Text3-Text4。

但是,我只想要文字1 。我不想在第一个 - 之后的所有文字。

我尝试过很多方法而没有成功。感谢帮助。

3 个答案:

答案 0 :(得分:2)

您可以使用GLSL shader load error (stage 1 shader 40): ERROR: 0.40: Initializer not allowed substring

indexOf

var text = 'Text 1-Text2-Text3-Text4'; alert(text.substring(0, text.indexOf('-'))); 将从substring索引获取子字符串到0索引。

答案 1 :(得分:1)

您可以将其拆分为<div style="width: 1000px; height: 500px; overflow-x:scroll; padding: 5px; display:inline-block; float:left;" > <div id="slider4" class="text-center"> <div class="slide-img"> <img src="img/team/team1.png"> <p style="font-weight: bold;">B Madhuprasad</p> <p>Chairman,</p> <p>Non-Executive</p> </div> <div class="slide-img"> <img src="img/team/team2.png"> <p style="font-weight: bold;">Vineet Suchanti</p> <p>Managing </p> <p>Director</p> </div> <div class="slide-img"> <img src="img/team/team3.png"> <p style="font-weight: bold;">Uday Patil</p> <p>Director,</p> <p>ECM</p> </div> <div class="slide-img"> <img src="img/team/team4.png"> <p style="font-weight: bold;">Rakesh Choudhari</p> <p>Managing Director, </p> <p>Stock Broking</p> </div> <div class="slide-img"> <img src="img/team/team5.png"> <p style="font-weight: bold;">Radha Kirthivasan</p> <p>Senior Vice President,</p> <p>EDM</p> </div> <div class="slide-img"> <img src="img/team/team6.png"> <p style="font-weight: bold;">Nipun Lodha</p> <p>Head,</p> <p>Investment Banking</p> </div> <div class="slide-img"> <img src="img/team/team07.png"> <p style="font-weight: bold;">Nilesh Dhruv</p> <p>Head,</p> <p>Equity Dealing</p> </div> <div class="slide-img"> <img src="img/team/team08.png"> <p style="font-weight: bold;">Jayraj Nair</p> <p>Head, </p> <p>Depositories</p> </div> <div class="slide-img"> <img src="img/team/team09.png"> <p style="font-weight: bold;">Ankur Mestry</p> <p>Head, <br/>Mutual Funds & <br/>IPO Distribution</p> </div> <div class="slide-img"> <img src="img/team/team10.png"> <p style="font-weight: bold;">Cherian MJ</p> <p>Vice President, </p> <p>Keynote ESOP</p> </div> </div> </div> </div> 并获取第一个元素。 -返回一个数组,其0索引处的第一个元素将为您提供所需的文本。

(记住索引从0开始,所以第一个是0,第二个是1,依此类推。)

String.split

答案 2 :(得分:0)

var str = "Text 1-Text2-Text3-Text4"
str.substr(0,str.indexOf("-"))

它将解决您的问题。