开发者

Populae value of input into span....Jquery?

I have an input, that you can increment up or down with a button.

I just want the number in that input field to populate a span.

        <div>
            <input type="text" name="balls" id="ballsLeft" value="48"/>
        </div>

<span id="ballsleftholde开发者_JAVA技巧r"></span>


Call the val() on your <input> element and use one of the following:


.html(htmlString)

Set the HTML contents of each element in the set of matched elements.

$("#ballsleftholder").html($("#ballsLeft").val());

.text(textString)

Set the content of each element in the set of matched elements to the specified text.

$("#ballsleftholder").text($("#ballsLeft").val());


It should seems like:

$('#ballsLeft').keyup(function() {
  $("#ballsleftholder").text($("#ballsLeft").val());
});


Bind change event to that input field and in that event do something like this

$('#ballsLeftHolder').html($(this).val());

You can also use keyup, keydown events. Just find what will exactly fit for your need.

Checkout this link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜