我正在尝试创建一个控件,您可以在其中选择要在表单中提交的文件,并将文件放入其中以执行相同的操作.我有这样的东西,如果它是一个图像,它也会显示该文件的预览:
<div class="preview-image-container">
<input type="file" name="File" id="File" accept="image/*"
class="image-url form-control" style="display:none;" />
<div class="preview-image-dummy"></div><img class="preview-image-url" />
<div class="preview-image-instruction">
<div class="preview-image-btn-browse btn btn-primary">Select file</div>
<p>or drop it here.</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
用户删除文件preview-image-container.该文件未随AJAX提交,用户需要提交包含更多数据的表单.
出于安全原因,我们不允许使用JavaScript更改输入文件的值.但是,我知道默认输入文件支持droppable,并且有一些网站让我们通过将它们放在表单中来选择文件,所以我的猜测是有一种方法可以做到这一点.
正如您从MCVE中看到的,我只对使用jQuery或纯JavaScript而不使用其他库感兴趣.
虽然可以使用dropzone.js,但它不符合我的要求,需要花费大量的时间来定制它的外观.此外,dropzone.js具有某些在我的ASP.NET应用程序中无法满足的配置要求.
有一个类似的问题,但没有一个正确的答案:
如何在HTML格式的表单中将文件对象设置为输入文件?
也不像上传拖放图像输入文件和预览,因为我已经实现了拖放和预览操作.我的问题是特定于在父容器中删除文件时输入空文件的问题.
我正在寻找一种在整个程序中设置语言环境的方法,如果可能的话.
我在我的main函数中设置了这样的语言环境:
int main()
{
setlocale(LC_ALL, "");
....
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,它并没有在整个程序中将语言环境设置为我的不同类/方法.我宁愿不在每个将在屏幕上打印并创建C++语言环境对象并传递给它的方法之上编写此行. "我觉得很可以接受.
感谢您的时间.
我的项目需要基本的增量算法和循环,以保持模板可读并用值填充 9x9 网格。这些值存储在字符串数组中,因此必须能够控制索引。
这是我定义了两个模板函数的处理程序:
func HomeHandler(w http.ResponseWriter, req *http.Request) {
t := template.New("home.html").Funcs(template.FuncMap{
"loop": func(n int) []struct{} {
return make([]struct{}, n)
},
}).Funcs(template.FuncMap{
"inc": func(n int) int {
return n + 1
},
})
t, err := t.ParseFiles("templates/home.html")
if err != nil {
log.Print("template/home error:", err)
}
t.ExecuteTemplate(w, "home.html", nil)
}
Run Code Online (Sandbox Code Playgroud)
要创建网格,我使用循环函数,如下所示:
{{ range loop 3}}
<tbody>
{{ range loop 3}}
<tr>
{{ range loop 9}}
<td> <input value="1" type="text" name="value[]" maxlength="1" size="1">
{{end}}
{{end}}
{{end}}
Run Code Online (Sandbox Code Playgroud)
但是,我想使用我的数据将 input 元素的 value …
我一直在关注这个答案,以揭示我的用户控件的一些属性.
问题是绑定找不到源,我不明白如何正确地做到这一点.
XAML:
<UserControl x:Class="Project.UI.Views.ucFilterDataGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Project.UI.Views"
xmlns:watermark="clr-namespace:Project.UI.Watermark"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,0,00,30"/>
</Style>
</StackPanel.Resources>
<AdornerDecorator>
<TextBox Name="SearchTextBox">
<watermark:WatermarkService.Watermark>
<TextBlock Name="waterMarkText"
Text="{Binding Path=WatermarkContent,
RelativeSource={RelativeSource FindAncestor,
AncestorType=local:ucFilterDataGrid}}"
HorizontalAlignment="Center" >
</TextBlock>
</watermark:WatermarkService.Watermark>
</TextBox>
</AdornerDecorator>
<DataGrid Name="Results">
</DataGrid>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
CS:
namespace Project.UI.Views
{
/// <summary>
/// Interaction logic for ucFilterDataGrid.xaml
/// </summary>
public partial class ucFilterDataGrid : UserControl
{
public ucFilterDataGrid()
{
InitializeComponent();
}
public string WatermarkContent
{
get { return GetValue(WatermarkContentProperty).ToString(); …Run Code Online (Sandbox Code Playgroud) c# ×1
c++ ×1
data-binding ×1
events ×1
file ×1
forms ×1
global ×1
go ×1
go-templates ×1
javascript ×1
jquery ×1
locale ×1
wpf ×1
xaml ×1