おはよう、私はckeditor
で記事のコンテンツを作ろうとしています。ここに私の入力からの例があります。jQueryまたはJavaScriptを使用してテキストから画像を抽出することはできますか?
<p>I have two images <img alt="" src="http://localhost:84/lf//assets/images/commingsoon.png" style="height:225px; width:225px" /> and this <img alt="" src="http://localhost:84/lf//assets/images/article2.jpg" style="height:91px; width:122px" /></p>
ご覧のとおり、2つの画像があり、最初の画像をサムネイルとして表示します。今のところ、私はそれを抽出したいだけです。
抽出物からの結果は、この
http://localhost:84/lf//assets/images/commingsoon.png
のようなものである
var myString = '<p>I have two images <img alt="" src="http://localhost:84/lf//assets/images/commingsoon.png" style="height:225px; width:225px" /> and this <img alt="" src="http://localhost:84/lf//assets/images/article2.jpg" style="height:91px; width:122px" /></p>';
var result = (someprosess)
あなたは(IMG).ATTR( 'SRC')この$を試してみました。 –
もっと明確にするには、最初に 'img'変数を設定してください。 'var img = $(" img ")[0]'は最初の画像を取得し、 '[1]'は第2の画像を取得します。次に、 'var imgSrc = $(img).attr(" src ")'を実行することができます。 – Naltroc