Javascriptを使用してタイトルタグの一部を抽出する方法を知っている人はいますか? 同様に、タイトル タグ内のダッシュ文字までのすべてのテキストを抽出し、ダッシュ文字の後のテキストは抽出しません。
例
<title>Extract this text-But not text after the dash</title>
Javascriptを使用してタイトルタグの一部を抽出する方法を知っている人はいますか? 同様に、タイトル タグ内のダッシュ文字までのすべてのテキストを抽出し、ダッシュ文字の後のテキストは抽出しません。
例
<title>Extract this text-But not text after the dash</title>
これを試して:
document.title.split('-')[0]
var title = document.title;
var dashIdx = title.indexOf("-");
var part = title.substring(0, dashIdx);
document.title.substring(0, document.title.indexOf('-'))
var dTt = document.title;
dTt.substring(0, dTt.indexOf('-'));
参照: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String#Methods