我如何使用jquery获取img路径

时间:2013-08-24 17:49:27

标签: javascript jquery

           <div class="em-main" style="text-align: center">
        <div class="em-div-head" align="center"> E-Shop Jewellery </div>
           <div class="em-textbox" style="border:hidden">
              <input type="text" value="To:" name="recipient" style="width:97%">
           </div>
        <div id="em">
             <div class="em-middle">
              <div style="border-bottom:solid 1px #CCCCCC">
              <textarea class="em-textarea" onblur="if (this.value == '') { this.value='Write a 
                message..'; }" onfocus="if(this.value == 'Write a message..') { this.value = 
                  ''; }" value="Write a message.." name="message">Write a message..</textarea>
            </div>
            <div id="em_rt_tp_scroller" class="em_rt_tp_scroller">
            <div id="em-rightscrollerimage" style="border:none">
     <div class="em-mdimage"><img class="mail" src=" http://localhost:8080/weather
       /servlets.ImgDisplayServlet?id=D:\EML\workspace\assets\tried-
         imgs\18__1882_IMG_5731_203_173.png " alt="imagecontainer image" style="max-
           height:100%; max-width:100%;">
         <ul>
        <img id="em-delete" class="removeicon" width="7" height="7" title="Remove" bottom="10%" 
          src="jqe13/image/delete_s.PNG">
          </ul>
         </div>
         <div class="em-mdimage">
           <img class="mail" src=" http://localhost:8080/weather
              /servlets.ImgDisplayServlet?id=D:\EML\workspace\assets\tried-
              imgs\13__1882_IMG_5731_120_124.png " alt="imagecontainer image" style="max-
                height:100%; max-width:100%;">
             <ul>
             <img id="em-delete" class="removeicon" width="7" height="7" title="Remove"        
                  bottom="10%" src="jqe13/image/delete_s.PNG">
             </ul> 
         </div>
         <div class="em-mdimage">
          <img class="mail" src=" http://localhost:8080/weather
             /servlets.ImgDisplayServlet?id=D:\EML\workspace\assets\tried-
              imgs\15__1882_IMG_5731_341_137.png " alt="imagecontainer image" style="max-
               height:100%; max-width:100%;">
             <ul>
              <img id="em-delete" class="removeicon" width="7" height="7" title="Remove"    
                bottom="10%" src="jqe13/image/delete_s.PNG">
             </ul>
            </div>
           </div>
         </div>
        </div>
         <div class="em-bottom" align="center">
             <input id="SEND" type="button" value="send" name="">
              <input id="CANCEL" type="button" value="cancel" name="">
         </div>
       </div>
      </div>

上面的代码正在运行包含图像源的邮件的html代码。我正在附加3张图片      到了class =“em-mdimage”。可以帮助我获取所有3个图像路径(如D:\ EML)     \ workspace \ assets \ trying-imgs \ 18__1882_IMG_5731_203_173.png)使用jquery。然后我将发送      单击“发送”按钮时,我的servlet的3个路径。   我是jquery的新手。我尝试了一些选择器,但我没有得到那些路径。   提前谢谢。

2 个答案:

答案 0 :(得分:1)

无法获取系统文件路径(例如D:\EML\workspace\assets\tried-imgs\18__1882_IMG_5731_203_173.png

浏览器无法访问您的本地文件系统,毫无疑问,JavaScript也无法访问远程文件系统。

您只需获取图片src属性

即可
$("img").each(function(){
  console.log($(this).attr("src"));
});

答案 1 :(得分:-1)

这对你有用, alert($('img')[0] .src);