Javascript 更改通过Jquery和AJAX动态加载到DIV中的HTML页面元素的样式
我有一个ajax调用,它通过ajax将HTML页面加载到div中。一旦页面加载到div中,就可以操作加载的HTML页面的内容。例如,一旦页面被加载到div中,我想用ID“1”设置其中一个图像的样式,使其周围有一个1像素的边框 下面是我用来将内容加载到div中的ajax代码Javascript 更改通过Jquery和AJAX动态加载到DIV中的HTML页面元素的样式,javascript,ajax,dom,jquery,Javascript,Ajax,Dom,Jquery,我有一个ajax调用,它通过ajax将HTML页面加载到div中。一旦页面加载到div中,就可以操作加载的HTML页面的内容。例如,一旦页面被加载到div中,我想用ID“1”设置其中一个图像的样式,使其周围有一个1像素的边框 下面是我用来将内容加载到div中的ajax代码 function getMessage(){ var sTitle = null; var sBody = null; var sImage = null; sImage = GetImageID(); $.ajax({
function getMessage(){
var sTitle = null;
var sBody = null;
var sImage = null;
sImage = GetImageID();
$.ajax({
type: "POST",
url: "xt_getAJAXData.asp",
data: {"cid":"3586",
"elid" :"2425",
"sText" : sBody,
"title" : sTitle,
"img" : sImage
},
success: function(resp){
// we have the response
var toLoad = 'sys_show_template.asp?step3=1&campaignid=3586'
$('.content').fadeOut('fast', loadContent);
$('#load').remove();
$('#waiting').append('<div id="load">Loading<br><img src="' + loadinggif + '" alt="Loading" /></div>');
$('#load').fadeIn('normal');
function loadContent() {
$('.content').load(toLoad, '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".content").html(msg + xhr.status + " " + xhr.statusText);
}
}).fadeIn('slow', hideLoader());
}
function hideLoader() {
$('#load').fadeOut('fast');
}
return false;
},
error: function (xmlHttpRequest, textStatus, errorThrown){
alert('Error: ' + xmlHttpRequest + " "+ textStatus + "" + errorThrown );
}
});
函数getMessage(){
var-sTitle=null;
var sBody=null;
var-sImage=null;
sImage=GetImageID();
$.ajax({
类型:“POST”,
url:“xt_getAJAXData.asp”,
数据:{“cid”:“3586”,
“elid”:“2425”,
“sText”:sBody,
“标题”:针,
“img”:sImage
},
成功:功能(resp){
//我们得到了答复
var toLoad='sys\u show\u template.asp?step3=1&campaid=3586'
$('.content').fadeOut('fast',loadContent);
$(“#加载”).remove();
$('#waiting').append('Loading'); $('加载').fadeIn('正常'); 函数loadContent(){ $('.content').load(toLoad',函数(响应、状态、xhr){ 如果(状态=‘错误’){ var msg=“抱歉,出现错误:”; $(“.content”).html(msg+xhr.status+“”+xhr.statusText); } }).fadeIn('slow',hideLoader()); } 函数hideLoader(){ $('加载').fadeOut('快速'); } 返回false; }, 错误:函数(xmlHttpRequest、textStatus、ErrorSprown){ 警报('Error:'+xmlHttpRequest+“”+textStatus+“”+errorshown); } }); } 然后在运行此代码的页面上,我尝试了 $('#1').css('border','solid 1px red') 这是HTML。这是一个电子邮件营销应用程序,这就是为什么我使用表
<table width="99%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td><img id="1" src="http://xxx.xxx.xx.xxx/upload/66/img_2873.jpg" border="0" width="180" alt="Property Picture"></td>
<td><img id="2" src="http://xxx.xxx.xx.xxx/upload/DD/img_2875.jpg" border="0" width="180" alt="Property Picture"></td>
<td><img id="3" src="http://xxx.xxx.xx.xxx/upload/77/img_2877.jpg" border="0" width="180" alt="Property Picture"></td>
</tr>
</table>
但由于id“#1”作为HTML流加载到div中,因此似乎无法从调用的页面访问它
是否可以通过jquery AJAX操作加载到页面中的元素ID#1的css属性,还是必须使用iFrame
提前谢谢 $(“..”).css在$中的响应文本上工作。ajax
附加到div
:
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Example document</title>
</head>
<body>
<p>Example paragraph</p>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function reskin()
{
$("#betamax").html(String(arguments[0].responseText).match(/<p.*/g)[0]);
$("#betamax p").css("color","blue");
}
function beta()
{
var alpha = alpha || $.ajax( {complete: reskin} );
$("body").append(String('<div id="betamax"></div>') );
}
beta();
</script>
</body>
</html>
示例文件
示例段
函数reskin()
{
$(“#betamax”).html(字符串(参数[0].responseText).match(/$(“…)).css在$的responseText
上工作。ajax
附加到div
:
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Example document</title>
</head>
<body>
<p>Example paragraph</p>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function reskin()
{
$("#betamax").html(String(arguments[0].responseText).match(/<p.*/g)[0]);
$("#betamax p").css("color","blue");
}
function beta()
{
var alpha = alpha || $.ajax( {complete: reskin} );
$("body").append(String('<div id="betamax"></div>') );
}
beta();
</script>
</body>
</html>
示例文件
示例段
函数reskin()
{
$(“#betamax”).html(字符串(参数[0].responseText).match(/IDs不能以数字开头。谢谢,我不知道。但是ID的名称与问题的目的无关,我可以将ID设置为任何内容。请显示您试图更改的HTML。只需将HTML snippit添加到post@Diodeus,。ID不能以数字开头。谢谢,我不知道。但是ID的名称与问题的目的我可以使id成为任何东西。请显示您试图更改的HTML。只需将HTML snippit添加到post@Diodeus, .