2012-03-20 58 views
5

更新:愚蠢的我没有注意到CASE是不确切的。我为此挣扎了30多分钟,你们看到我的问题不到5!谢谢你救了我很多悲伤 - 我对编程有点新东西,我需要学习如何看待这样的小事情,但非常感谢,它甚至没有跨过我的脑海:)JQuery找不到我的元素。为什么?

对不起大家 - 因为我忘了引号,我的问题它之前误导,但我可以向你保证,我知道,jQuery的选择需要加引号,我一直在使用他们...

<div id='question' style="background-color:#DAE2E8;border-color:#A2B3C7;border-width:1px;border-style:solid"><br /> 
    <table id='searchtable' border='0'> 
     <tr> 
      <td><span class="label">Question ID:</span><input id='QuestionId' type='text'/></td> 
      <td><span class="label">Question Title:</span><input id='QuestionTitle' type='text'/></td> 
      <td><span class="label">Original URL:</span><input id='OriginalURL' type='text'/></td> 
      <td><span class="label">Original Title:</span><input id='OriginalTitle' type='text' /></td> 
      <td><span class="label">Chronic ID:</span><input id='ChronicID' type='text' /></td> 
     </tr><tr> 
      <td><span class="label">Expert Name:</span><input id='ExpertName' type='text'/></td> 
      <td><span class="label">Topic ID:</span><input id='TopicID' type='text'/></td> 
      <td><span class="label">Channel ID:</span><input id='ChennelID' type='text''/></td> 
      <td><span class="label">Funded: </span><input id='IsFunded' type='text'/></td> 
      <td><span class="label">Funded Partner:</span><input id='FundedPartner' type='text'/></td> 
     </tr><tr> 
      <td><input type="submit" value="Submit" onclick='ApplyNewFilters(this)' /></td> 
     </tr> 
    </table> 
</div> 

所以这里是我的HTML代码(它在一个aspx页面中) - 我尝试使用$("#QuestionID").val()来获取值,但它不起作用。我也试过$("input#QuestionID").val()

+0

你能CONSOLE.LOG错误?如果您尝试'console.log($(“#QuestionID”));' – SpYk3HH 2012-03-20 20:35:48

+0

应该返回一些东西不知道如何记录错误。现在它只是告诉我,它是未定义的。 – egucciar 2012-03-20 20:38:06

+0

@gdoron我对JQuery非常陌生。我来自一个CSharp背景,所以Javascript仍然是一个完整的球场。你对如何访问/任何好的资源查看DOM以及如何使用jQuery – egucciar 2012-03-20 20:49:55

回答

10

尝试使用:

$("#QuestionId").val() 

注意的报价和详细情况。

​​3210

+0

对不起,我刚刚编辑了我的文章,因为我忘了把报价放在那里。不,这绝对不是问题。我一直在使用引号这整个时间><我的ID,所以我不知道什么在 – egucciar 2012-03-20 20:36:59

+0

去之前已经选择的东西QuestionId不QuestionID – deltree 2012-03-20 20:37:41

+0

@ user1274649注意的情况下'QuestionID'和'QuestionId' - 的'D' – 2012-03-20 20:37:59

4

你确定你使用的是正确的呢?

$("#QuestionId").val()应该工作

如果它不能正常工作,请检查您的Firebug的控制台选项卡,查看是否有在页面

+0

的报价是否有 – 2012-03-20 20:36:55

+0

@adam:他现在编辑。 – Shyju 2012-03-20 20:37:49

+0

这不是报价,它是CASE !!哇和我一直在为这个该死的东西奋斗至少30分钟。现在我知道我再也不会做这样的疏忽了。非常感谢您的注意:) – egucciar 2012-03-20 20:44:22

3

一些脚本错误输入ID被QuestionId不QuestionID

1

您错过了选择器上的引号。它应该是$('#QuestionId').val()$('input#QuestionId').val()

2

的选择是区分大小写的,所以你拼写错误的“ID”

$("#QuestionId").val() 

应该工作。

+1

是的,它也谢谢你米<3 – egucciar 2012-03-20 20:46:47

1

尝试在该行

<input id='ChennelID' type='text''/> 
+0

感谢指出了这一点 – egucciar 2012-03-20 20:50:30

1

<td><span class="label">Channel ID:</span><input id='ChennelID' type='text''/></td> 

纠正双引号,这

<td><span class="label">Channel ID:</span><input id='ChennelID' type='text' /></td> 

你和额外'在案件结束

你正在使用

<asp:TextBox /> 

必须创建与ASP客户端ID

var ChannelID = <%=txtChannelID.ClientID %> 

其中的clientid是文本框名称的值在JavaScript的一个变种

+0

有用的信息 - 感谢注意到,其他的报价,这将有救了我很多痛苦 – egucciar 2012-03-20 20:47:51