0
我想在输入或按下按钮时调用JavaScript函数。另外,我想让函数检索值。呼叫功能按下Enter或点击按钮
这里是我的形式:
<form>
Farm Number:<br>
<input id="fnumber" type="text" value="" onKeyDown="findfarm2(event)">
<input type="button" value="Find Farm" onclick="findfarm();"> \t
</form>
,这里是我的JavaScript函数:
function findfarm2(event) {
\t \t if (event.keyCode == 13){
\t \t cqlfilter = 'Farm =' + document.getElementById('fnumber').value; \t \t
\t \t unregistered.getSource().updateParams({'LAYERS': 'NCSPCTest:Unreported_Names','CQL_FILTER': cqlfilter}); \t \t
\t \t alert(cqlfilter)
\t \t }
\t \t }
\t \t
function findfarm() {
\t \t cqlfilter = 'Farm =' + document.getElementById('fnumber').value; \t \t
\t \t unregistered.getSource().updateParams({'LAYERS': 'NCSPCTest:Unreported_Names','CQL_FILTER': cqlfilter});
\t \t alert(cqlfilter)
\t \t } \t
的按钮B工作输入功能不是。 'findfarm2'函数可以弹出警报,但不会将值传递给'updateParams'。
也许ENTER键只有在焦点位于按钮上时才会起作用。 – mariodiniz