我正在尝试使用jquery:contains()选择器来查找我的问题并从中删除该类,但是在这种情况下,我遇到了语法错误问题,在下面显示了我的代码。
var question = 'A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8';
$('.wrap .view_all_que:contains('+question+')').parent('li').removeClass('current-question');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="wrap">
<ul>
<li class="current-question">
<i class="fa fa-bookmark" aria-hidden="true"></i>
<span class="question-dot"></span>
<a class="view_all_que">
<p>A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8</p>
</a>
</li>
</ul>
</div>
它告诉我:
未捕获的错误:语法错误,无法识别的表达式:.wrap .view_all_que:contains(渗透测试仪正在进行端口扫描 在特定主机上。测试人员发现打开了几个端口 导致安装的操作系统(OS)版本混乱。 考虑以下NMAP结果,以下哪个可能是 通过操作系统安装在目标计算机上?在以下位置启动NMAP 5.21 2011-03-15 11:06 172.16.40.65主机的NMAP扫描报告已启动(1.00s 潜伏)。未显示:993关闭的端口PORT STATE SERVICE 21 / tcp打开 ftp 23 / tcp打开telnet 80 / tcp打开http 139 / tcp打开netbios-ssn 515 / tcp打开631 / tec打开ipp 9100 / tcp打开MAC地址: 00:00:48:0D:EE:8)
有人可以帮我吗?
答案 0 :(得分:3)
您需要将搜索表达式用引号引起来,例如
$('.wrap .view_all_que:contains("' + question + '")').parent('li').removeClass('current-question');
答案 1 :(得分:1)
您错过了在变量问题周围添加quotes
的问题。尝试这样。
$('.wrap .view_all_que:contains("'+question+'")')
var question = 'A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8';
$('.wrap .view_all_que:contains("'+question+'")').parent('li').removeClass('current-question');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="wrap">
<ul>
<li class="current-question">
<i class="fa fa-bookmark" aria-hidden="true"></i>
<span class="question-dot"></span>
<a class="view_all_que">
<p>A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8</p>
</a>
</li>
</ul>
</div>
答案 2 :(得分:1)
您错过了双引号!添加它们,它将按您的意愿工作
var question = 'A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8';
$('.wrap .view_all_que:contains("'+question+'")').parent('li').removeClass('current-question');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="wrap">
<ul>
<li class="current-question">
<i class="fa fa-bookmark" aria-hidden="true"></i>
<span class="question-dot"></span>
<a class="view_all_que">
<p>A penetration tester is conducting a port scan on a specific host. The tester found several ports opened that were confusing in concluding the Operating System (OS) version installed. Considering the NMAP result below, which of the follow is likely to be installed on the target machine by the OS? Starting NMAP 5.21 at 2011-03-15 11:06 NMAP scan report for 172.16.40.65 Host is up (1.00s latency). Not shown: 993 closed ports PORT STATE SERVICE 21/tcp open ftp 23/tcp open telnet 80 /tcp open http 139/tcp open netbios-ssn 515/tcp open 631/tec open ipp 9100/tcp open MAC Address: 00:00:48:0D:EE:8</p>
</a>
</li>
</ul>
</div>