上传文件限制文件格式js 及浏览框左面的text框只读

jsp :限制用户输入路径

<td height="58" class="b" valign="bottom">
                    <div align="left"><input type="file" name="address" unselectable="on" style="WIDTH:400px"/></div>
</td> 

js 验证图片格式:

/**---------判断是否是图片,符合格式:jpg gif bmp,png,jpeg*/
function isPicture(fileName){
       if(fileName!=null && fileName !=""){
      //lastIndexOf如果没有搜索到则返回为-1
      if (fileName.lastIndexOf(".")!=-1) {
   var fileType = (fileName.substring(fileName.lastIndexOf(".")+1,fileName.length)).toLowerCase();
   var suppotFile = new Array();
   suppotFile[0] = "jpg";
                        suppotFile[1] = "gif";
                        suppotFile[2] = "bmp";
                        suppotFile[3] = "png";
                        suppotFile[4] = "jpeg";
   for (var i =0;i<suppotFile.length;i++) {
    if (suppotFile[i]==fileType) {
     return true;
    } else{
     continue;
    }
   }
   //alert("文件类型不合法,只能是jpg、gif、bmp、png、jpeg类型!");
   return false;
  } else{
   //alert("文件类型不合法,只能是 jpg、gif、bmp、png、jpeg 类型!");
                        return false;
  }
      }
}

jsp页面调用:

if(document.forms[0].upgradefile.value !=""){
         if(!isUpdatePack(document.forms[0].upgradefile.value)){
           alert("文件类型不合法,只能是jpg、gif、bmp、png、jpeg类型!");
           return false;
         }
       }

### WPF 实现窗口自适应布局的方法 #### 使用 ViewBox 控件实现自适应布局 为了使控件能够随着窗口大小的变化而自动调整,可以利用 `ViewBox` 控件。此控件会根据可用的空间比例放大或缩小其内部的内容[^2]。 ```xml <Window x:Class="WpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="MainWindow"> <Grid> <!-- 使用 ViewBox 来包裹其他控件 --> <Viewbox Stretch="Uniform"> <StackPanel Orientation="Vertical"> <TextBlock Text="这是一个测试文本"/> <Button Content="点击这里"/> </StackPanel> </Viewbox> </Grid> </Window> ``` 上述代码片段展示了如何通过 `Stretch="Uniform"` 属性来确保内容在缩放过程中保持原有的宽高比[^3]。 #### 设置 Grid 布局以支持动态调整 除了使用 `ViewBox` 外,在设计复杂的界面时还可以考虑采用 `Grid` 容器,并合理配置行和列的定义方式以便更好地响应不同的屏幕尺寸[^1]。 ```xml <Window x:Class="WpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="MainWindow"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBox Grid.Row="0" Margin="5"/> <ListBox Grid.Row="1" ItemsSource="{Binding SomeItems}" Margin="5"/> <Button Grid.Row="2" Content="Submit" HorizontalAlignment="Center"/> </Grid> </Window> ``` 在这个例子中,第一行的高度被设定为 `Auto` 使得它只占用所需的空间;第二行为默认高度,允许其中的内容自由扩展;最后一行则设置了星号 (`*`) 表示剩余空间将由这一行列共享。 #### 利用 Star (*) 单位分配空间 当涉及到多行或多列的情况下,可以通过指定星号单位(*)的方式让多个区域按照一定比例分享容器内的可利用面积。例如: ```xml <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> ``` 这表示左边一栏占据三分之一宽度,右边两倍于左面那一栏所占有的宽度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值