如何根据变量更改div宽度

时间:2016-06-09 09:29:56

标签: javascript jquery css

我有table可编辑。我希望在div内容更改时更改td宽度。我认为我的jQuery代码不起作用。我该如何解决这个问题?



var form = document.getElementById('form');
number = document.getElementById('number');
form.onchange = function() {
  var variable = number.value;
  var unit = "px";
  var z = variable + unit;
  $("#check").css("width", z);
};

#check {
  background-color: red;
  height: 15px;
  width: 200px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <form id="form">
        <input id="number" type="number" min="1" name="number">
      </form>
      <div id="check"></div>
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以在 Notification noti = new Notification.Builder(mContext) .setContentTitle("New mail from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .setLargeIcon(aBitmap) .build(); keyup

中使用jquery

change
var form = document.getElementById('form');
number = document.getElementById('number');
$("#number").on("keyup change",function() {
  var variable = number.value;
  var unit = "px";
  var z = variable + unit;
  $("#check").css("width", z);
});
#check {
  background-color: red;
  height: 15px;
  width: 200px;
}