错误:语法错误,无法识别的表达式:#192.168.1.3:8985_solr“

时间:2019-08-09 11:08:29

标签: javascript jquery

我遇到JavaScript错误。

  

错误:语法错误,无法识别的表达式:#192.168.1.3:8985_solr

var replicasNodeName = "192.168.1.209:8983_solr";
$('"#' + replicasNodeName + '"').append('<a href="#"><span class="badge">5</span></a>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card">
  <div class="card-body" id="192.168.1.209:8983_solr"> </div>
</div>

3 个答案:

答案 0 :(得分:1)

另一种方法是,使用本机import os import numpy as np import math import cv2 as cv #path = '/media/D/code/OCR/text-detection-ctpn/data/mlt_english+chinese/image' gt_file = '12.txt' output = open("temp.txt","w") with open(gt_file, 'r') as f: for line in f: line = line.replace("[", "") line = line.replace("(", "") line = line.replace(")", "") line = line.replace("]", "") line = line.replace(" ", "") output.write(line) output.close() os.remove(gt_file) # remove old file os.rename("temp.txt",gt_file) # rename as old file 方法,则无需转义元字符

document.getElementById()
var replicasNodeName = "192.168.1.209:8983_solr";
$(document.getElementById(replicasNodeName)).append('<a href="#"><span class="badge">5</span></a>');

答案 1 :(得分:0)

您需要对.:字符进行转义,因为它们在选择器中具有特殊含义。为此,请在它们之前加上\\。您也不需要字符串中的多余引号。试试这个:

var replicasNodeName = "192\\.168\\.1\\.209\\:8983_solr";
$('#' + replicasNodeName).append('<a href="#"><span class="badge">5</span></a>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card">
  <div class="card-body" id="192.168.1.209:8983_solr"> </div>
</div>

答案 2 :(得分:0)

另一种没有任何转义的解决方案是:

请参见jQuery Selectors以供参考

INamed
var replicasNodeName = "192.168.1.209:8983_solr";
$("*[id='"+ replicasNodeName + "'").append('<a href="#"><span class="badge">5</span></a>');