JQuery can't find my Element. Why?

2019-06-21 07:41发布

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:)

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...

<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().

7条回答
贪生不怕死
2楼-- · 2019-06-21 08:18

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

查看更多
Animai°情兽
3楼-- · 2019-06-21 08:22

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

var ChannelID = <%=txtChannelID.ClientID %>

where clientid is the text box name

查看更多
老娘就宠你
4楼-- · 2019-06-21 08:27

Are you sure you are using the correct case ?

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

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

查看更多
戒情不戒烟
5楼-- · 2019-06-21 08:29

Try correcting the double quote at the line

<input id='ChennelID' type='text''/>
查看更多
看我几分像从前
6楼-- · 2019-06-21 08:32

Try using:

$("#QuestionId").val()

Note the quotes and exact case.

Example here

查看更多
相关推荐>>
7楼-- · 2019-06-21 08:38

the input id is QuestionId not QuestionID

查看更多
登录 后发表回答