如何将文本附加到jquery的div?

时间:2015-12-14 06:37:08

标签: javascript jquery

我使用jquery附加它但它永远不会显示在下拉列表中

<DataGrid x:Name="Grid" ItemsSource="{Binding}">
   <DataGrid.CellStyle>
      <Style TargetType="DataGridCell">
        <Style.Triggers>
           <DataTrigger Binding="{Binding Path=YourProperty}" Value="10">
               <Setter Property="Label.Background" Value="Green" />
           </DataTrigger>
         </Style.Triggers>
      </Style>
   </DataGrid.CellStyle>
</DataGrid>

3 个答案:

答案 0 :(得分:2)

你在类名中使用了一些意想不到的空格,\ n,你应该删除那些

您的代码就像

    $(".notiDiv").append('<div class="row" style="margin: 1px"><div class="col-sm-8"><a href="#!">user have created a meeting</a></div><div class="form-group col-sm-4 text-right"  ><a href="#!"><span class=" glyphicon glyphicon-ok"></span></a><a href="#!" ><span class=" glyphicon glyphicon-remove"></span></a></div></div>');

答案 1 :(得分:0)

一旦你修复了所有的JS错误,如Satpal所建议的那样;您将需要以编程方式初始化引导程序下拉列表,如下所示:

for (var key in data)
 {
    //alert(data[key]["type"] + data[key]["id"] + data[key]["message"]);
    //$str = $str+;
    $(".notiDiv").append('<div class="row" style="margin: 1px">\n\<div class="col - sm - 8">\n\<a href="#">' user have created a meeting'</a>\n\</div>\n\<div class="form - group col - sm - 4 text - right"  >\n\<a><span class=" glyphicon glyphicon - ok"></span></a>\n\<a><span class=" glyphicon glyphicon - remove"></span></a>\n\</div>\n\</div>\n');
 }
 $(".notiDiv").dropdown(); //re-init dropdowm once all options has been appended

答案 2 :(得分:0)

您可以在这里查看代码,我已经为您创建了一个示例

http://plnkr.co/edit/seRGvP?p=preview

$( document ).ready(function() {
  var data = {
    "flammable": "inflammable",
    "duh": "no duh"
  };
  $.each(data, function( key, value ) {
    //alert( key + ": " + value );
    $(".notiDiv").append('<div class="row" style="margin: 1px">\n\<div class="col - sm - 8">\n\<a href="#">' + value + '</a>\n\</div>\n\<div class="form - group col - sm - 4 text - right"  >\n\<a><span class=" glyphicon glyphicon - ok"></span></a>\n\<a><span class=" glyphicon glyphicon - remove"></span></a>\n\</div>\n\</div>\n');
  });
});

或使用数组

$( document ).ready(function() {
   var data = ['aaaaaaaaaaaa','bbbbbbbbbbbbbb','ccccccccccccc','dddddddddddd','eeeeeeeeeeee','ffffffffffffff','ggggggggggg','jjjjjjjjjjjj'];
   $(data).each( function( index, value ) {
      //alert( index + ": " + value );
       //$( ".notiDiv" ).append( value );
       $(".notiDiv").append('<div class="row" style="margin: 1px">\n\<div class="col - sm - 8">\n\<a href="#">' + value + '</a>\n\</div>\n\<div class="form - group col - sm - 4 text - right"  >\n\<a><span class=" glyphicon glyphicon - ok"></span></a>\n\<a><span class=" glyphicon glyphicon - remove"></span></a>\n\</div>\n\</div>\n');
    });
});