javascript JQuery 找不到我的元素。为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9794491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:51:56  来源:igfitidea点击:

JQuery can't find my Element. Why?

javascriptjqueryhtmlinputjquery-selectors

提问by egucciar

UPDATE: Silly me didn't notice that the CASE wasn't exact. I was struggling with this for 30+ minutes, and you guys saw my problem in less than 5!! thanks for saving me a lot of grief - I'm kind of new to programming anyway,I need to learn how to look out for little things like this, but thanks so much, it had not even crossed my mind:)

更新:愚蠢的我没有注意到 CASE 不准确。我为此苦苦挣扎了 30 多分钟,你们不到 5 分钟就看到了我的问题!!感谢您为我省去了很多悲伤 - 无论如何,我对编程有点陌生,我需要学习如何注意这样的小事,但非常感谢,我什至没有想到它:)

Sorry everyone - It was misleading before because I forgot to put quotes in my question, but I can assure you I know that the selector for Jquery requires quotes and I've been using them...

对不起大家 - 之前这是误导,因为我忘记在我的问题中加上引号,但我可以向你保证我知道 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>

So here is my HTML code (its in an aspx page) - I tried using $("#QuestionID").val()to get the value, but it won't work. I also tried $("input#QuestionID").val().

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

回答by RedFilter

Try using:

尝试使用:

$("#QuestionId").val()

Note the quotes and exact case.

注意引号和确切的大小写。

Example here

示例在这里

回答by Shyju

Are you sure you are using the correct case ?

您确定您使用的是正确的大小写吗?

$("#QuestionId").val()should work

$("#QuestionId").val()应该管用

If it is not working, go and check your firebug console tab to see whether there is some script error in the page

如果它不起作用,请检查您的 firebug 控制台选项卡以查看页面中是否存在某些脚本错误

回答by Darren

the input id is QuestionId not QuestionID

输入 id 是 QuestionId 不是 QuestionID

回答by everton

The selectors are case-sensitive, so you've mispelled the "Id"

选择器区分大小写,所以你拼错了“Id”

$("#QuestionId").val()

Should work.

应该管用。

回答by Cristian Lupascu

Try correcting the double quote at the line

尝试更正该行的双引号

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

回答by chepe263

look

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

and this

还有这个

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

you have and extra ' at the end

你在最后有额外的 '

in case you are using

如果您正在使用

<asp:TextBox /> 

you must create a var on javascript with the value of the asp client id

您必须使用 asp 客户端 ID 的值在 javascript 上创建一个 var

var ChannelID = <%=txtChannelID.ClientID %>

where clientid is the text box name

其中 clientid 是文本框名称

回答by jmoerdyk

You're missing the quote marks on your selectors. It should be $('#QuestionId').val()or $('input#QuestionId').val()

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