JS intercept suffix name, full file name, non-suffix Method---collection (cold _)

Source: Internet
Author: User

<script language= "javascript" type= "Text/javascript" >

Take the path of the entire file and assign the filename to the filename

var isTrue = true;

function GetName (obj) {

Checktype (obj);

if (isTrue) {

Hide Control Assignment

var hfexname = document.getelementbyidx_x ("<%=hfexname.clientid%>");

Hfexname.value = GetFileName (Obj.value);

Service Control text Box JQ notation

Id= "Txtname" <asp:textbox/>

$ ("#<%=txtname.clientid%> input") [0].value = Getfilenamenoext (Obj.value);

GetFileName (Obj.value);

}

}

String reversal

function Strturn (str)

{

if (str! = "") {var str1 = "";

for (var i = str.length-1;i >= 0; i--) {str1 + = Str.charat (i);

} return (STR1);

} }

restricting file types

function Checktype (obj) {

if (Obj.value.length > 0) {var af = "Txt,docx,doc,docm,dotx,dotm,pptx,accdb,vsd,xlsx,xlsm,xltx,xlsb,xlam";

if (Eval_r ("with (Obj.value)

if (!/"+ af.split (", "). Join (" | ") +"/ig.test (substring (lastIndexOf (') ') +1,length))) 1; "))

{Alert ("Support for uploading file type: \ n" + af);

IsTrue = false;

}else {isTrue = true;

} }

else {

IsTrue = false; } }

Take file suffix name

function Getfileext (filepath) {if (filepath! = "") {var pos = "." + Filepath.replace (/.+\./, ""); return POS; } }

Take file name without suffix

function Getfilenamenoext (filepath) {var pos = Strturn (Getfileext (filepath));

var file = Strturn (filepath);

var pos1 =strturn (File.replace (POS, ""));

var pos2 = GetFileName (POS1);

return pos2;

}

Take file Full name

function GetFileName (filepath) {if (filepath! = ") {var names = filepath.split (" \ \ ");

return names[names.length-1];

} }

Dynamic binding file Detail type

function DataBind (e, s) {

$.ajax ({

Type: "POST", Processdata:false,

Transfer by post

URL: '.. /ajaxrequestpages/sellcontract/ajax_sellpactfilemanager.aspx? Filetypeid= ' + s.getvalue (),

Destination Address

Success:setddlfptype});

Success:function (JSON)); }

callback function

function Setddlfptype (HTMLS)

{

if (htmls! = NULL && htmls! = "")

{

var L = htmls.length; var html = left (htmls, L-1);

var FTT = Ddlfptype; Ftt.clearitems ();

var htmllist = Html.split (', ');

for (i = 0; i < htmllist.length; i++) {Ftt.additem (htmllist[i].split (' = ') [1], htmllist[i].split (' = ') [0]);

}

Ftt.setselectedindex (0);

By default the first person on the

} else {

Alert ("An exception occurred when getting the verbose type!") ");

} }

Remove the last character of a string

function left (MAINSTR, Lnglen)

{

if (Lnglen > 0) {

Return mainstr.substring (0, Lnglen)

} else

{

return null

}} </script>

<asp:fileupload id= "FileUpload" runat= "Server" onfocus= "GetName (This)"/>

JS 2 Update

<script language= "javascript" type= "Text/javascript" >

Takes the path of the entire file and assigns the file name to the file name var isTrue = true; function GetName (obj) {checktype (obj);

if (isTrue)

{var hfexname = document.getelementbyidx_x ("<%=hfexname.clientid%>");

Hfexname.value = GetFileName (Obj.value); $ ("#<%=txtstandardname.clientid%> input") [0].value = Getfilenamenoext (Obj.value);

GetFileName (Obj.value);

Document.getelementbyidx_x ("<%=txtstandardname.clientid%>"). Value = Getfilenamenoext (Obj.value); } }

restricting file types

function Checktype (obj) {

if (Obj.value.length > 0)

{

var af = "Txt,docx,doc,docm,dotx,dotm,pptx,accdb,vsd,xlsx,xlsm,xltx,xlsb,xlam";

if (Eval_r ("with (Obj.value) if (!/" + af.split (","). Join ("|") + "/ig.test (substring ('. ') +1,length))) 1; ")) {Alert ("Support for uploading file type: \ n" + af);

IsTrue = false;

} else {isTrue = true;

}} else {

IsTrue = false;

} }

Take file suffix name

function Getfileext (filepath) {if (filepath! = "") {var pos = "." + Filepath.replace (/.+\./, ""); return POS;

} }

Take file name without suffix

function Getfilenamenoext (filepath) {if (filepath! = ") {var names = filepath.split (" \ \ ");

var pos = Names[names.length-1].lastindexof ("."); Return names[names.length-1].substring (0, POS);

} }

Take file Full name

function GetFileName (filepath) {if (filepath! = "")

{var names = filepath.split ("\ \");

return names[names.length-1]; }

}

</script>

JS intercept suffix name, full file name, non-suffix Method---collection (cold _)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.