我正在尝试从两个字符之间的字符串中提取信息并附加它。我能够让它在指定的字符之间拉出第一个,但我无法让它输出所有这些。任何帮助都将非常感谢。
var $feed = "stuff I don't want: stuff to pull; stuff I don't want: stuff to pull two; stuff I don't want: stuff to pull three;";
var $startMarker = $feed.indexOf(':');
var $endMarker = $feed.indexOf(';',$startMarker);
var $text = $feed.substring($startMarker,$endMarker)
$( "div" ).append("<p>" + $text + "</p>");
我也在玩:
var $text2 = $feed.split(':')[3].split(';')[0];
$( "div" ).append("<p>" + $text2 + "</p>");
答案 0 :(得分:1)
<强> Demo 强>
var feed = "stuff I don't want: stuff to pull; stuff I don't want: stuff to pull two; stuff I don't want: stuff to pull three;";
var semiSplit=feed.split(";");
$( "div" ).append("<p>" + semiSplit[0] + "</p>");
$( "div" ).append("<p>" + semiSplit[1] + "</p>");
$( "div" ).append("<p>" + semiSplit[2] + "</p>");
只需要提取 Working Demo
var semiSplitLen=semiSplit.length;
for(var i=0;i<semiSplitLen-1;i++){
var getStup=semiSplit[i].split(":");
$( "div" ).append("<p>" + getStup[1] + "</p>");
}