使用逗号分隔符将文本替换为图像标记

时间:2015-12-02 12:21:51

标签: javascript jquery html

代码正在使用jquery,我正在尝试使用逗号分隔符将文本更改为图像标记,因此每个单词都需要图像标记。在这种情况下,当图像被替换时,30度清洗已经消失。



<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Untitled Document</title>
        <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script>
            $(document).ready(function() {
                $('.pa_wash .attribute-value:contains("iron")').html('<img src="edit.png"/>');
            });
        </script>
    </head>
    <body>
        <li class="pa_wash">
            <span class="attribute-label">Wash :  </span>
            <span class="attribute-value">30 Degree Wash, iron</span>
        </li>
    </body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

var posOptions = {timeout: 10000, enableHighAccuracy: false};
var myOptions = '';

$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
  var getLat  = position.coords.latitude
  var getLong = position.coords.longitude
  myOptions = {
    zoom: 16,
    center: new google.maps.LatLng(getLat, getLong),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  console.log(getLat);
  var map = new google.maps.Map(document.getElementById("map"), myOptions);
}, function(err) {
  // error
});

您需要将$(document).ready(function () { $('.pa_wash .attribute-value:contains("iron")').html(function () { return this.innerHTML .replace("iron", '<img src="edit_0.png"/>') .replace("30 Degree Wash", '<img src="edit_1.png"/>'); }); }); 替换为您的图片,然后再次设置iron

Working fiddle