how to get a table value that inside an iframe
I am trying to get values from a table that lives inside an iframe using jquery but so far with no luck.
i have tried this code:
$('#childframe').contents().bind("dblclick", function() {
var code = $('#childframe').contents().find('.priceName').text();
alert(code);
return false; }):
but i am getting the text of the entire td for that column. because i am using gridview sap.net control i can't set the ID for that td and I am forced to define the CssClass to "pric开发者_JAVA技巧eName".
"childframe" is the ID for my iframe.
This should get you the text for the element that is double clicked:
$('#childframe').contents().bind("dblclick", function() {
alert($(this).text());
});
Here's a working example: http://jsfiddle.net/K9P9q/30/
EDIT
If you're having a difficult time getting this to work, here's another suggestion (this assumes that you control that page being loaded in the iframe).
- Do your click binding in the iframe itself. This should simplify the jquery binding code.
- In your click handler function within the iframe, invoke a function on the parent and pass the text of the selected TD to the parent. Example below.
jQuery inside iframe
$('#[tableIdHere]').bind("dblclick", function() {
parent.HandleTdDoubleClick($(this).text());
});
Hander inside parent
function HandleTdDoubleClick(txt)
{
alert(txt);
}
精彩评论