我正在尝试使用 jQuery 的 typeWatch 插件。我有这个 JavaScript:
<script type="text/javascript">
$(document).ready(function() {
var options = {
callback: function() { alert("a-ok! " + $(this).text); },
wait: 333,
highlight: true,
captureLength: 1
}
$("#customer").typeWatch(options);
});
</script>
我的 View 的 HTML 是这样的:
Method B: <%= Html.TextBox("customer") %>
通过此测试,如果我在文本框中输入“ABC”,我期望弹出一个带有“a-ok! ABC”的警报。相反,出现以下内容...
a-ok! function (F) {
if (typeof F !== "object" && F != null) {
return this.empty().append((this[0] && this[0].ownerDocument ||
document).createTextNode(F));
}
var E = "";
o.each(F || this, function () {o.each(this.childNodes, function () {
if (this.nodeType != 8) {
E += this.nodeType != 1 ? this.nodeValue : o.fn.text([this]);}});});
return E;
}
我尝试将 $(this).text 更改为 .val,并且还尝试将输入字段更直接地引用为 $("#customer"),但它们会产生类似的结果。我怎样才能只访问输入的文本?
最佳答案
您应该在文本框上使用 val() 函数:
$(this).val();
关于javascript - 如何使用 jQuery 访问输入字段文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/944697/