JQuery issues with SharePoint
I am having a strange problem with jQuery inside sharepoint. My jQuery code works fine in Web Applications but when I use the same code on a Web Part it creates problem.
Here is the problem with jQuery in Web Parts. I have external JavaScript file which I reference on my web part.
This is my function in a separate JavaScript file.
function CallJS() {
开发者_运维知识库 alert($("#txt1")); **// It returns the object**
alert($('#txt1').attr('value')); **// Always return 'undefined'**
return false;
}
My development environment is VS2008, SharePoint 2007 and jQuery version is 1.4.4.
First try to pass value using jquery attribute like this $('#txt1').attr('value','Test')
after passing value try this $('#txt1').attr('value')
it returs your value.
In you case solution is that use $('#txt1').val()
, or try to pass value dynamically than you can access that value using attribute method.
精彩评论