开发者

possible to pass variable to javascript function from html form like this?

<form><input type="file" name="first" onchange="jsFunction(2);">
<开发者_JS百科input type="file" name="second" onchange="jsFunction(3);"</form>

Possible to pass just numbers to the js function?

Thanks


Yes, it is possible :)


That is definitely plausible, however, the onChange event is only fired when the input has changed AND it loses focus.


Sure, you can do this. What you are really doing here is creating a function on the fly. Your jsFuction executes when the page loads, not when the value changes. So, its return value should be a function--the function that you want to execute when the value changes. For example:

function jsFunction(number) {
  return function () {
    var currentValue = this.value;
    alert('I was given ' + number + ' and the current value is ' + currentValue);
  };
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜