您的位置:首页 > Web前端 > JavaScript

IE、Firefox兼容form target当前页iframe,javascript动态创建表单对象form设置name属性

2011-09-07 15:01 1046 查看
一、

不兼容的测试代码:

<body>

<form action="http://www.baidu.com" method="post" id="form_forwrad_forword" >

<input type="submit" value="submit"/>

</form>

<iframe id="loginIframe" width="300" height="300"></iframe>

</body>

</html>

<script language="javascript">

var _form=document.getElementById("form_forwrad_forword");

_form.setAttribute("target","loginIframe");

</script>

IE:点击“submit”提交之后,form表单并未按照预想提交到“loginIframe”这个iframe中。

FF:点击“submit”提交之后,form表单按照预想提交到“loginIframe”这个iframe中。

解决此兼容问题: 在iframe中增加name属性即name=“loginIframe”

<iframe id="loginIframe" name="loginIframe" width="300" height="300"></iframe>

二、解决javascript动态创建表单对象form设置name属性(IE、FF兼容)

function AFTER_FORMCREATE_FN(){

var _iframe;

try { // for I.E.

_iframe= document.createElement('<iframe name="loginIframe">');

} catch (ex) { //for other browsers, an exception will be thrown

_iframe = document.createElement('iframe');

}

_iframe.setAttribute("id","loginIframe");

_iframe.setAttribute("name","loginIframe");

_iframe.setAttribute("height","300");

_iframe.setAttribute("style","display:none;");

document.body.appendChild(_iframe);

var _form=document.getElementById("form_forwrad_forword");

_form.setAttribute("target","loginIframe");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐