简体   繁体   English

引导文字对齐:左侧为空输入-右侧为填充输入

[英]Bootstrap text align: Empty input left - Filled input right

Has Bootstrap a built in feature to align the placeholder in an empty text-input on the left, and if the user enters a number (→ filled input) to the right. 具有Bootstrap内置功能,可将占位符与左侧的空白文本输入对齐,如果用户在右侧输入数字(→ 填充输入)。

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <div class="form-group"> <div class="input-group"> <input class="form-control" maxlength="255" placeholder="Amount" name="amount" type="text" value="" id="amount"> <span class="input-group-addon financing">€</span> </div> </div> 

I think that it may be this what you are looking for. 我认为这可能就是您要寻找的。

$('#amount').on('keyup', function(){
if($('#amount').val().length > 0)
  $('#amount').css('text-align', 'right');
else
  $('#amount').css('text-align', 'left');
});

http://codepen.io/powaznypowazny/pen/JWXvYE http://codepen.io/powaznypowazny/pen/JWXvYE

No Bootstrap does not have this built in but input dir="rtl" might be close enough? 没有Bootstrap没有内置此功能,但输入dir =“ rtl”可能足够接近?

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <div class="form-group"> <div class="input-group"> <input dir="rtl" class="form-control" maxlength="255" placeholder="Amount" name="amount" type="text" value="" id="amount"> <span class="input-group-addon financing">€</span> </div> </div> 

 <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script> <script> $(document).ready(function(){ $("#amount").keyup(function(){ var val = $(this).val(); if(val == ''){ $(this).css('text-align','right'); }else{ $(this).css('text-align','left'); } }) }) </script> 

easy to use jquery 易于使用的jQuery

只需在输入中使用dir="rtl"

<input dir="rtl" placeholder="Amount" name="amount" type="text">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM