jquery无法从input元素中获取值

sil*_*r27 0 jquery select text input case-sensitive

我正在使用jquery尝试检索文本输入的值,但它无法正常工作.谁能看到我做错了什么?http://jsfiddle.net/silvajeff/rJNLr/

<input id="mytest2" value="123"/>
<button id="findRow">Find Row</button>

$("#findRow").click(function() {   
  var theVal = $("#myTest2").val();
  alert(theVal);
});
Run Code Online (Sandbox Code Playgroud)

我向所有人道歉,但我最初发布的内容只是一个错字,当我打破这个问题以简化它时.我将不得不重新发布,只是这次我将把未经简化的代码放在这里.我会在这里留下这个问题并添加一个区分大小写的标签,因为我仍然认为这些对于可能存在问题的其他人来说是有价值的解决方案.

Arv*_*waj 6

更改$("#myTest2")$("#mytest2")


Adi*_*dil 6

你使用了错误的id myTest2,这是不存在的用途mytest2.Javascript 区分大小写,因此您需要注意.

现场演示

$("#findRow").click(function() {   
  var theVal = $("#mytest2").val();
  alert(theVal);
});
Run Code Online (Sandbox Code Playgroud)


The*_*bit 6

您错误地提到了字段的"id"值.

id值在jQuery中是CASE SENSITIVE

因此,改变

myTest2到mytest2