Form表单提交按钮图片IE6下背景透明(js提交)
我们知道 光png图片在IE6下面透明方法很多,网上也很多,但是我今天遇到了个难题:form表单提交按钮png图片要求背景透明。我弄了半天,转个思维,Form提交方法:1,大家都知道的submit提交;2,js提交,只有这样才能使png背景透明.
上面要求我做的是一个搜索框:直接上代码:
<form action="search.php" name="formAddress" id="formAddress" method="post">
<input type="text" size="33" name="usearch" class="skuang" />
<a href="javascript:addressadd();" name="submit" id="savesubmit">
<img src="p_w_picpaths/Search_btn.png" class="into" />
</a>
</form>
js控制提交代码:
<script>function addressadd(){document.formAddress.submit();}</script>
js使png图片透明代码(记得把这个加到头部head之间):
<script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var j=0; j<document.p_w_picpaths.length; j++)
{
var img = document.p_w_picpaths[j]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
j = j-1
}
}
}
}
window.attachEvent(" correctPNG);
</script>
总结:有时候想问题不能太死板,要灵活,这条路走不通,就不走,换条路走,条条道路通罗马。
转载于:https://blog.51cto.com/xuqin/925198