1

タイトルから最初の3文字を削除する必要があります。私が使用した:

$(".layered_subtitle").each(function() {
var text = $(this).text();
text = text.replace('06.', '');
$(this).text(text);

番号付きのタイトルを動的にロードしました:

01.title

02.title

03.title..

削除する文字を区切る方法は?

4

8 に答える 8

1

これまでの答えは大丈夫ですが、将来の使用のために別の方法で行う必要があると思います。カウントが増える可能性があるので、「。」の最初の出現を検索してください。そこで弦を切ります。

text = text.substring(text.indexOf(".")+1);
于 2012-09-15T10:08:08.243 に答える
1

これを使用できます (最初の引数に正の整数のみを使用する場合に実質的に同じslice/ substring/関連の JavaScript 関数の中で最も短い):substr

text = text.slice(3);
于 2012-09-15T10:04:38.170 に答える
0

次のような部分文字列メソッドを使用できます。

$(".layered_subtitle").each(function() {
    var text = $(this).text();
    if(text && text.length > 3){
        text = text.substring(3)
        $(this).text(text);
    }
});

ajaxリクエストの成功時にこれを行う必要がある場合:

function removeChars(){
   $(".layered_subtitle").each(function() {
       var text = $(this).text();
       if(text && text.length > 3){
           text = text.substring(3)
           $(this).text(text);
       }
   });
}
var serializedData = {};//Fill data
$.ajax({
    url: "url",
    type: "post",//post or get
    data: serializedData,
    // callback handler that will be called on success
    success: function (){
        //Add here logic where you update DOM
        //(in your case add divs with layered_subtitle class)
        //Now there is new data on page where we need to remove chars
        removeChars();
    }
});
于 2012-09-15T10:06:47.697 に答える
0

これを試して

text = text.substring(3)

それ以外の

text = text.replace('06.', '');
于 2012-09-15T10:08:27.027 に答える
0

セパレーター(ポイント)の正確な位置がわからない場合は、次の場所を見つける必要があります。

var newText = oldText.substr(oldText.indexOf('.') + 1);

または、区切り文字の後に多くの数字またはスペース文字が見つかる場合は、正規表現を使用する必要があります。

var newText = oldText.replace(/^\d+\.\s*/, "");

どちらも機能します。

于 2012-09-15T10:14:59.843 に答える
0

JavaScript 部分文字列を使用するだけです:

text = text.substring(3);
于 2012-09-15T10:01:09.983 に答える
0

このようにしてみてください

text = text.substr(3);
alert(text);
$(this).text(text);
于 2012-09-15T10:02:10.497 に答える
0

タイトルが 3 文字以上の場合は、最初の 3 文字を削除できます。

if (text.length >= 3) text = test.substring(3);

正規表現を使用して、「nn.xxxx」の形式に一致する場合にのみ番号を削除できます。

 text = text.replace(/^\d\d\./, '');
于 2012-09-15T10:25:19.593 に答える