在项目中碰到如下一个问题:
? 通过Ajax返回一个字符串,其中包含有一个链接信息,是用来设置页面上iframe的src的、、、
?
function showResponse(responseText, statusText) {
??? var res = jQuery.trim(responseText).split("||");
??? if(res[0].indexOf(". ")>0){
??? ??? res[0] = res[0].replace(". ",".\r\n");
??? }
??? $("#msg").val(res[0]);
??? if(null!=res[1]&&""!=res[1]){
??? ??? //$("#preShowValueIFrame").attr("src",res[1]);
??????? //document.getElementById("preShowValueIFrame").src=res[1];
??? ??? document.getElementById("preShowValueIFrame").setAttribute("src",res[1]);
??? }
}
?
文中红色加粗部分,对于被注释掉的两种设置方法,在IE7下面会报错“invalid argument”。
最后查到通过setAttribute方法来进行设值,ok,搞定了、、、O(∩_∩)O~