jquery selector can't read from hidden field

后端 未结 6 1240
孤独总比滥情好
孤独总比滥情好 2020-12-16 15:06

(answers aggregated into another question)

The following jquery 1.3.2 code works:



        
6条回答
  •  忘掉有多难
    2020-12-16 15:44

    If you're doing this in ASP.Net, check the ID of your control at runtime via the View Source option in your browser. You might find that your control ID isn't what you expect it to be if, for example, your control is declared in a content page. In this case it would be assigned an ID that's driven by its master page. Rather than hard-coding the ID in your jQuery you can refer to its ClientID property using ASP.Net inline syntax which will also protect you from any changes in the master or content page control hierarchy.

    So...

    $('#<%= myHiddenControl.ClientID %>').val();
    

    ...would be a better choice than ...

    $('#ctl00_ContentPlaceHolder1_ctl00_ContentPlaceHolder1_myHiddenControl').val();
    

    ...although they would both work.

提交回复
热议问题