嘿所有我试图找到所有标签 data-required =" true" 以找到它下面的下一个范围并添加*到
$('[data-required="True"]').next("span").append(
"<i class='icon-asterisk' style='color: rgba(255, 46, 49, 1);'>*</i> "
);
&#13;
td,th{padding:0;white-space:nowrap}table{border-spacing:0;border-collapse:collapse;background-color:transparent}body{margin:0;padding-top:0;padding-bottom:0}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:10px;-webkit-tap-highlight-color:transparent}*,::after,::before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}input,select,textarea{max-width:300px;cursor:pointer}body,html{height:100%}::after,::before{content:""}.input-group{position:relative;display:table;border-collapse:separate}.mCustomScrollbar{-ms-touch-action:pinch-zoom;touch-action:pinch-zoom}.input-group .form-control{position:relative;float:left;width:100%;margin-bottom:0;z-index:inherit}.input-group .form-control,.input-group-addon,.input-group-btn{display:table-cell}.input-group-addon,.input-group-btn{width:1%;white-space:nowrap;vertical-align:middle}.input-group-addon{padding:6px 12px;font-size:14px;font-weight:400;line-height:1;color:#555;text-align:center;background-color:#eee;border:1px solid #ccc;border-radius:4px;box-shadow:0 2px 2px rgba(150,150,150,.3)}.form-inline .form-control{box-shadow:0 2px 2px rgba(150,150,150,.3);border-radius:0 4px 4px 0}.form-inline .input-group .form-control,.form-inline .input-group .input-group-addon,.form-inline .input-group .input-group-btn{width:auto}.input-group:not(:first-child):not(:last-child).form-control,:not(:first-child):not(:last-child).input-group-addon,:not(:first-child):not(:last-child).input-group-btn{border-radius:0}.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9{float:left}.col-sm-10{width:83.33%}button,input,optgroup,select,textarea{margin:0;font:inherit;color:inherit}button,input,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}.form-control{display:block;width:100%;height:34px;padding:6px 12px;font-size:14px;line-height:1.4285;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.form-control,.input-sm{left:0}input[type=text]{width:auto;border:1px solid #CCC}.form-inline .form-control{display:inline-block;width:auto;vertical-align:middle}.input-group:first-child.form-control,:first-child.input-group-addon,:first-child.input-group-btn>.btn,:first-child.input-group-btn>.btn-group>.btn,:first-child.input-group-btn>.dropdown-toggle,:last-child.input-group-btn>:not(:last-child).btn-group>.btn,:last-child.input-group-btn>:not(:last-child):not(.dropdown-toggle).btn{border-top-right-radius:0;border-bottom-right-radius:0}.input-group:last-child.form-control,:first-child.input-group-btn>:not(:first-child).btn,:first-child.input-group-btn>:not(:first-child).btn-group>.btn,:last-child.input-group-addon,:last-child.input-group-btn>.btn,:last-child.input-group-btn>.btn-group>.btn,:last-child.input-group-btn>.dropdown-toggle{border-top-left-radius:0;border-bottom-left-radius:0;box-shadow:0 2px 2px rgba(150,150,150,.3)}.glyphicon{position:relative;top:1px;display:inline-block;font-family:"Glyphicons Halflings";font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-user::before{content:"\e008"}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
<td>
<label class="control-label" style="width: 0px; max-width: 0px; padding: 150px;" for="EstimateCost" data-required="True" data-definedas="num" data-base="tTrip"> </label>
</td>
<td>
<div class="input-group">
<span style="left: 10px; top: -12px; width: 300px; position: absolute;">Estimated Cost</span>
<div class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</div>
<div class="col-sm-10">
<input name="EstimateCost" class="tips form-control" id="EstimateCost" style="width: 99px;" type="text" value="" data-tooltip="example ">
</div>
</div>
</td>
</tr>
&#13;
示例文字估算费用应变为估算费用* ,但不是。
像这样做 .next(&#34; span&#34;):
$('[data-required="True"]').next("span").append(...)
似乎没有产生我想要的东西。有什么帮助吗?
答案 0 :(得分:2)
next()
无效,it targets only siblings,而您的span
不是label
的兄弟。
这将获得父(<td>
),它紧跟在元素(下一个<td>
),find
所有<span>
的子元素之后<td>
,将匹配的集合简化为first
元素,append
a&#34; *&#34;它。
$('[data-required="True"]').each(function(){
$(this).parent().next().find('span').first().append('*');
});
你能否编辑标记?即在跨度中添加一个类?