访问使用 Iframe 呈现的 html 中的文本区域,它本身是用 cshtml 页面加载的
To access the text area in the html rendered using Iframe which itself is loaded withing a cshtml page
我在 Cshtml 页面中加载了一个 iframe。 Iframe 包含一个 html 表单。当加载主页(cshtml 页面)时,我需要在表单的每个文本区域前面添加一个图像。已经尝试了很多东西,但没有任何效果。下面是我正在尝试的代码:
$("#iframe").ready(function() {
$.each($('input[type=text],textarea'), function() {
var idOfCurrentElement = $(this).attr('id');
var classNameOfCurrentElement = $(this).attr('class');
var visibilityOfCurrentElement = $(this).css('visibility');
if(classNameOfCurrentElement != "hidden" && visibilityOfCurrentElement == "visible")
$("<img src='~/images/pic' alt='Pic'>");
});
});
您必须访问 iframe 内容,而不是您的页面。
$("#iframe").ready(function() {
$.each($('#iframe').contents().find('input[type=text],textarea'), function() {
var $thatButton = $(this);
var idOfCurrentElement = thatButton .attr('id');
var classNameOfCurrentElement = thatButton ).attr('class');
var visibilityOfCurrentElement = thatButton .css('visibility');
if(classNameOfCurrentElement != "hidden" && visibilityOfCurrentElement == "visible")
//do what you want.
});
});
我在 Cshtml 页面中加载了一个 iframe。 Iframe 包含一个 html 表单。当加载主页(cshtml 页面)时,我需要在表单的每个文本区域前面添加一个图像。已经尝试了很多东西,但没有任何效果。下面是我正在尝试的代码:
$("#iframe").ready(function() {
$.each($('input[type=text],textarea'), function() {
var idOfCurrentElement = $(this).attr('id');
var classNameOfCurrentElement = $(this).attr('class');
var visibilityOfCurrentElement = $(this).css('visibility');
if(classNameOfCurrentElement != "hidden" && visibilityOfCurrentElement == "visible")
$("<img src='~/images/pic' alt='Pic'>");
});
});
您必须访问 iframe 内容,而不是您的页面。
$("#iframe").ready(function() {
$.each($('#iframe').contents().find('input[type=text],textarea'), function() {
var $thatButton = $(this);
var idOfCurrentElement = thatButton .attr('id');
var classNameOfCurrentElement = thatButton ).attr('class');
var visibilityOfCurrentElement = thatButton .css('visibility');
if(classNameOfCurrentElement != "hidden" && visibilityOfCurrentElement == "visible")
//do what you want.
});
});