Not sure what exactly you're trying to do, but the following works (fiddle):
function change(variable) {
var value = $(variable).val();
alert(value);
$(variable).html(value);
}
سؤال
I have 4 input boxes that call a function when the key is lifted using the onkeyup
event. For some reason, I am getting an error saying that "change" (the function's name) is not defined. I am definitely defining the function correctly, so I have no idea what's causing this.
The demo will explain much better than me:
(source: snag.gy)
OK, got it. I was getting that error, but the cause what not what I had suspected. http://jsfiddle.net/qWcZ6/2/
المحلول
Not sure what exactly you're trying to do, but the following works (fiddle):
function change(variable) {
var value = $(variable).val();
alert(value);
$(variable).html(value);
}
نصائح أخرى
This is a better pattern.
<mtext><input id="y" value="y" class="vars"></input></mtext>
<mo>=</mo>
<mtext><input id="m" value="m" class="vars"></input></mtext>
<mo>×</mo>
<mtext><input id="x" value="x" class="vars"></input></mtext>
<mo>+</mo>
<mtext><input id="b" value="b" class="vars"></input></mtext>
$(document).ready(function(){
function change() {
var value = $(this).val();
//alert(value);
if (console && typeof console.log !== 'undefined') {
console.log("value",value);
}
}
$('.vars').on('keyup',change);
});