我知道这个问题已经被问了很多,但我似乎无法找到我正在寻找的答案。我收到了这个错误:
Uncaught TypeError: $(...).find(...).hasClass(...).val is not a function
at attach_selectors (commercial.js:768)
at HTMLDocument.<anonymous> (commercial.js:117)
at j (jquery-1.11.0.min.js:2)
at Object.fireWith [as resolveWith] (jquery-1.11.0.min.js:2)
at Function.ready (jquery-1.11.0.min.js:2)
at HTMLDocument.K (jquery-1.11.0.min.js:2)
我知道它与val()有关,但是如果有人能指出我正确的方向那将是伟大的。我需要创建一个新功能吗?
var stInput=$("form").find("input").hasClass("st-search").val();
$("#submitSearch").off("click").on("click", function(e) {
e.preventDefault();
$(".gsc-search-button").find(stInput).click();
}
);
&#13;
<form class="st-search">
<div class="gcse-search"><input type="text" class="st-default-search-input" placeholder="Search..." />
<xsl:text> </xsl:text>
</div>
<button class="btn btn-secondary-bel gsc-search-button gsc-search-button-v2" id="submitSearch" title="search">Search</button>
</form>
&#13;
答案 0 :(得分:2)
此行返回布尔值而不是jQuery对象
var stInput = $("form").find("input").hasClass("st-search");
您可能希望这样做:
var stInput = $("form").find("input").val();
答案 1 :(得分:2)
mMap.moveCamera(CameraUpdateFactory.newLatLng(mLatLng));
会返回import java.util.stream.*;
import java.math.BigInteger;
public class Primes {
public static IntStream stream() {
return IntStream.iterate( 3, i -> i + 2 ).parallel()
.filter( i -> i % 3 != 0 ).mapToObj( BigInteger::valueOf )
.filter( i -> i.isProbablePrime( 1 ) == true )
.flatMapToInt( i -> IntStream.of( i.intValue() ) );
}
}
或hasClass
,它们没有true
功能。也许您想将选择器调整为false
?
答案 2 :(得分:2)
答案 3 :(得分:0)
添加了代码段并删除hasClass()
,因为此函数返回一个布尔值。
var stInput = $("form").find("input").val();
$("#submitSearch").off("click").on("click", function(e) {
e.preventDefault();
//Update value
stInput = $("form").find("input").val()
console.log(stInput);
$(".gsc-search-button").find(stInput).click();
}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="st-search">
<div class="gcse-search"><input type="text" class="st-default-search-input" placeholder="Search..." />
<xsl:text> </xsl:text>
</div>
<button class="btn btn-secondary-bel gsc-search-button gsc-search-button-v2" id="submitSearch" title="search">Search</button>
</form>
答案 4 :(得分:0)
hasClass()函数只返回布尔值。
var data = $("form").find("input").val();
var stInput = $(".st-default-search-input").val();
$("#submitSearch").off("click").on("click", function(e) {
e.preventDefault();
$(".gsc-search-button").find(stInput).click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<form class="st-search"><div class="gcse-search"><input type="text" class="st-default-search-input" placeholder="Search..." /><xsl:text> </xsl:text></div>
<button class="btn btn-secondary-bel gsc-search-button gsc-search-button-v2" id="submitSearch" title="search">Search</button>
</form>