javascript - Check for null or empty value in placeholder text - Stack Overflow

I have a dust.js template that renders inputs based on a hash I am getting from the server. My hangup i

I have a dust.js template that renders inputs based on a hash I am getting from the server. My hangup is that if the hash is empty I still get an input box rendered with an empty placeholder value, how can I check if the placeholder value is null and then hide that box?

<div class='criteria-input'>
  <input type='text' placeholder='{attribute}' value='{value}' size='20'/>
  <span class="close">X</span>
</div>

I have a dust.js template that renders inputs based on a hash I am getting from the server. My hangup is that if the hash is empty I still get an input box rendered with an empty placeholder value, how can I check if the placeholder value is null and then hide that box?

<div class='criteria-input'>
  <input type='text' placeholder='{attribute}' value='{value}' size='20'/>
  <span class="close">X</span>
</div>
Share Improve this question edited Jul 22, 2014 at 19:46 glortho 13.2k8 gold badges51 silver badges46 bronze badges asked Jul 22, 2014 at 19:30 mrtrianglemrtriangle 54411 silver badges28 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

See the "Special Sections" documentation of dust.js here: http://akdubya.github.io/dustjs/#guide

The "exists" syntax is what you want, so that you can do this:

{?attribute}
<div class='criteria-input'>
  <input type='text' placeholder='{attribute}' value='{value}' size='20'/>
  <span class="close">X</span>
</div>
{/attribute}

here you go:

$('input').each(function(){
    if($(this).attr('placeholder')=='' || $(this).attr('placeholder')==null){
        $(this).parent().hide();
    }
});

here is the code that checks if the placeholder is empy

var placeholder = $('input').attr('placeholder');
if(placeholder == ''){

} else{

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745100213a4611227.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信