filter()
возвращает значение. Проверьте, равна ли длина 1 или более.
$(".filter").click(function() {
var value = $(this).text(); //Get the text of the button
var result = $("div").hide().filter(function(i, o) { //Hide All and filter
return $(o).text().includes(value); //Return true if the content of div contains text of the button
}).show(); //Show all result
if (result.length) { //Check the length of the result
//Found match/es
$(".msg").text('');
} else {
//No match
$(".msg").text(`${value} not found`);
}
});
$(".show-all").click(function() {
$("div").show();
});
.msg {
border: 1px solid black;
}
div {
background-color: pink
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="msg"></span>
<br /><br />
<div> apple </div>
<div> orange </div>
<div> rock melon</div>
<div> pineapple </div>
<div> pineapple pie</div>
<br /><br />
<button class="filter">example</button>
<button class="filter">pineapple</button>
<button class="filter">rock</button>
<br /><br />
<button class="show-all">Show all</button>
org.apache.commons.httpclient. HttpClient является Вашим другом,
Пример кода из http://hc.apache.org/httpclient-3.x/sslguide.html
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setProxy("myproxyhost", 8080);
httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost",
new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password"));
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(httpget);
System.out.println(httpget.getStatusLine());
} finally {
httpget.releaseConnection();
}
с апачским commons-http-client 4: Вы найдете много примеров http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/
Необходимо установить java.net. Аутентификатор перед открытием соединения:
...
public static void main(String[] args) throws Exception {
// Set the username and password in a manner which doesn't leave it visible.
final String username = Console.readLine("[%s]", "Proxy Username");
final char[] password = Console.readPassword("[%s"], "Proxy Password:");
// Use a anonymous class for our authenticator for brevity
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
URL url = new URL("https://ssl.site");
...
}
Для удаления аутентификатора после того, как Вы будете закончены назовите следующий код:
Authenticator.setDefault(null);
Аутентификатор в Java SE 6 поддержек HTTP Basic
, HTTP Digest
и NTLM
. Для получения дополнительной информации см. документацию Аутентификации HTTP по sun.com