如何在输入字段中添加永久占位符

时间:2015-04-23 08:30:32

标签: html input font-awesome

我需要在输入字段中添加 private void CustomizableDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (!this.YearOnly) return; this.SetValue(SelectedYearProperty, SelectedDate.Value.Year); Binding bnd = new Binding { Path = new PropertyPath("SelectedDate"), StringFormat = ("yyyy"), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(CustomizableDatePicker), 1) }; this.innerTextBox.SetBinding(TextBox.CustomizableTextBox.TextProperty, bnd); } ,所以我使用了这个方法

 #region YearOnly DependencyProperty

    public bool YearOnly
    {
        get { return (bool)this.GetValue(YearOnlyProperty); }
        set { this.SetValue(YearOnlyProperty, value); }
    }

    public static readonly DependencyProperty YearOnlyProperty =
        DependencyProperty.Register("YearOnly",
        typeof(bool),
        typeof(CustomizableDatePicker),
        new FrameworkPropertyMetadata(false));

    #endregion

    #region SelectedYear DependencyProperty

    public int SelectedYear
    {
        get { return (int)this.GetValue(SelectedYearProperty); }
        set { this.SetValue(SelectedYearProperty, value); }
    }

    public static readonly DependencyProperty SelectedYearProperty =
        DependencyProperty.Register("SelectedYear",
        typeof(int),
        typeof(CustomizableDatePicker));

    #endregion

当你看到font-icon这个 <input type="text" name="your name" placeholder="&#xe00b; YOUR NAME" style="font-family:Flaticon" class="restrict"> 显示placeholder="&#xe00b; YOUR NAME"但我的问题是当用户输入一些文字占位符消失时,我需要将字体图标永久放置在输入字段内,如{{ 1}}

有人可以帮助我

1 个答案:

答案 0 :(得分:2)

你不能。你期望它看起来像什么? placeholder按设计消失

如果您希望在输入字段前面添加一个图标,请将它们放在一个容器中,为此容器提供所需的样式,然后放置您的图标和input - 标签。那就是how bootstrap your problem solves

Example of bootstrap.

缩短的例子:

<div class="input-group">
  <div class="input-group-addon">$</div>
  <input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
</div>

当然,你需要CSS。