The transparent stacked addition method is used to implement the operation without IFRAME.
Place the file field on the clicked span and make it transparent.
In this way, you can see the custom span click area, but not the area where the file is browsed.
Click the Browse button, which does not violate any security mechanism.
Reference position of the original method. Http://www.script8.com/bbs/thread.asp? Tid = 6
<HTML>
<Head>
<Title> test HTML </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style>
Body
{
Font-size: 12px;
Cursor: default;
}
. Hand
{
Cursor: pointer;
Cursor: hand;
}
. Btnfade
{
Position: absolute;
Padding-top: 3px;
Font-family:;
}
. Btnreal
{
Position: absolute;
Width: 60px;
Overflow: hidden;
Filter: alpha (opacity = 0 );
-Moz-opacity: 0;
}
. Fileelement
{
Float: left;
Margin-Right: 6;
Padding-top: 3;
Color: darkgreen;
}
</Style>
</Head>
<Body onload = "setup ();">
<Script language = "JavaScript" type = "text/JavaScript">
// Use the reload tech cocould hide some control UI.
Function setup (){
$ ("Btnreal "). innerhtml = "<input onchange = \" AddFile (this ); \ "type = \" file \ "size = \" 1 \ "class = \" hand \ "hidefocus = \" True \ "/> ";
}
Function AddFile (File ){
// Create object append filename.
VaR filename, fileelement;
Filename = file. value. Replace (// \/g, "/"). Replace (/(. * \/) (. *)/, "$2 ");
File. style. Display = "NONE ";
Fileelement = Document. createelement ("nobr"); // just want to display the file.
Fileelement. classname = "fileelement ";
Fileelement. innerhtml = "□" + filename; // Add the filename.
Fileelement. innerhtml + = "<font style = color: red; font-weight: bold; onclick = \" $ (filelist ). removechild (this. parentnode); \ "class = hand>" + Unescape ("×") + "</font>"; // Add the delete button.
$ ("Filelist"). insertbefore (fileelement, $ ("btnfile "));
Setup ();
}
Function $ (element ){
Return typeof (element) = "object "? Element: Document. getelementbyid (element );
}
</SCRIPT>
<Div id = "filelist">
<Div id = "btnfile" onmouseover = "$ (btnfade ). style. textdecoration = underline; "onmouseout =" $ (btnfade ). style. textdecoration = none; "style =" color: Navy "> <! -- This Div just want to display a hand. -->
<Span id = "btnfade" class = "btnfade" style = "cursor: Pointer" >### add an attachment </span>
<Span id = "btnreal" class = "btnreal" onmouseover = "This. scrollleft = 100px"> </span>
</Div>
</Div>
</Body>
</Html>