Can't seem to bind two text inputs together
I have two form inputs that I need have matching field content. Meaning if I enter text in one field it is the exact same on the other field (they are in separate forms).
I thought I could use .bind() to do it but my script would not allow my text to bind to another input.
var inp = $("#text1");
if ("onpropertychange" in inp)
inp.attachEve开发者_StackOverflownt($.proxy(function () {
if (event.propertyName == "value")
$("div").text(this.value);
}, inp));
else
inp.addEventListener("input", function () {
$("#text2").text(this.value);
}, false);
<input type="text" id="text1" />
<input type="text" id="text2" />
change keyup
to change
if you don`t want to edit it letter by letter; jsfiddle there
var $inputs = $('#input1, #input2');
$inputs.keyup(function(){
$inputs.val($(this).val());
});
$("#text1").change({
$("#text2").val(this.val());
});
What about this?
$('#input01').keyup(function() {
value = $(this).val();
$("#input02").val(value);
});
精彩评论