自分が達成したいことは、htmlの<section class = "film">の子である<p>の子のすべての<img>のソースパスを取得して、そのソースパスの最初の”images”をJavaScript のreplace()で"reviews"に変え、そして例えば、
<img src="images/Gone_With_the_Wind.jpg"の"jpg"を”xml”に変えたいのですが、**var finalXml = xmlName.replace("images","reviews");**このようにすると replace is not a functionと出てエラーになってしまいます。どうしたらreplace を使えるようになるのでしょうか??
```javaScript
/**
- Created by tkimura on 8/16/17.
*/
var Reviews = (function(){
var pub = {};
function showReviews(){ var target = $(this).parent().find(".review")[0]; var xmlName = $(this).parent().find("img")[0]; var finalXml = xmlName.replace("images", "reviews"); console.log(finalXml); } pub.setup = function(){ $('.film').append("<input type='button' class='showReviews' value='Show Reviews'>", "<div class='review'></div>"); $(".showReviews").click(showReviews); } return pub;
}());
$(document).ready(Reviews.setup);
var target = $(this).parent().find(".review")[0]; var xmlName = $(this).parent().find("img")[0]; **var finalXml = xmlName.replace("images","reviews");** ```HTML <!DOCTYPE html> <html lang="en"> <head> <title>Classic Cinema</title> <link rel="stylesheet" href="style.css"> <meta charset="utf-8"> <script src="showHide.js"></script> <script src="cookies.js"></script> <script src="cart.js"></script> <script src = "jquery-3.2.1.min.js"></script> <script src="showReviews.js"></script> </head> <body> <header> <h1>Classic Cinema</h1> </header> <div id="user"> <div id="login"> <form id="loginForm"> <label for="loginUser">Username: </label> <input type="text" name="loginUser" id="loginUser"> <label for="loginPassword">Password: </label> <input type="password" name="loginPassword" id="loginPassword"> <input type="submit" id="loginSubmit" value="Login"> </form> </div> <div id="logout"> <p>Welcome, <span id="logoutUser"></span></p> <form id="logoutForm"> <input type="submit" id="logoutSubmit" value="Logout"> </form> </div> </div> <nav> <ul> <li> <a href="index.html">Home</a> <li> Classics <li> <a href="scifi.html">Science Fiction and Horror</a> <li> <a href="hitchcock.html">Alfred Hitchcock</a> <li> <a href="checkout.html">Checkout</a> </ul> </nav> <div id="main"> <h2>Classic Films</h2> <section class="film"> <img src="images/Gone_With_the_Wind.jpg" alt="Gone With the Wind"> <h3>Gone With the Wind (1939)</h3> <p>Directed by: Victor Fleming, George Cukor, Sam Wood</p> <p>Starring: Clark Gable, Vivien Leigh, Leslie Howard, Olivia de Havilland, Hattie McDaniel</p> <p>An epic historical romance and winner of 8 Academy Awards (from 13 nominations).</p> <p> $<span class="price">13.99</span> <input type="button" value="Add to Cart" class="buy"> </p> </section> <section class="film"> <img src="images/The_Jazz_Singer.jpg" alt="The Jazz Singer"> <h3>The Jazz Singer (1927)</h3> <p>Directed by: Alan Crosland</p> <p>Starring: Al Jolson, May McAvoy, Warner Oland, Cantor Rosenblatt</p> <p>The first feature length 'talkie', The Jazz Singer is a piece of cinematic history</p> <p> $<span class="price">13.99</span> <input type="button" value="Add to Cart" class="buy"> </p> </section> <section class="film"> <img src="images/Metropolis.jpg" alt="Metropolis"> <h3>Metropolis (1927)</h3> <p>Directed by: Fritz Lang</p> <p>Starring: Alfred Abel, Brigitte Helm, Gustav Fröhlich, Rudolf Klein-Rogge</p> <p>A lovingly restored version of Fritz Lang's dystopian masterpiece, one of the great achievements of the silent era.</p> <p> $<span class="price">19.99</span> <input type="button" value="Add to Cart" class="buy"> </p> </section> </div> <footer> <p> Classic Cinema is not a real store. No products are available, and no money will be accepted. <p> All images from <a href="http://commons.wikimedia.org/wiki/Main_Page">Wikimedia Commons</a> and are believed to be in the public domain. </p> </footer> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。