调用两个jQuery函数,onChange

时间:2017-03-28 14:19:08

标签: jquery

嗨我在onChange事件中调用remotefunction。我想当用户从父下拉列表中选择时,将显示属于父ID的子下拉列表,但将隐藏默认子块。我如何在onchange事件中调用两个函数。

我的代码:

<g:select optionKey="id" from="${commonList}" class="fullBorderBox"  value="${value?."${propertyName}"?."${commonPropertyName}"?.id}" name="${commonPropertyName}.id" noSelection="${['null': message(code: 'common.list.select')]}"  onchange="${remoteFunction(
                      controller: 'middlewareData',
                      action: 'populateVersion',
                      params: "'typeId=' + this.value + '&&lookUpProperty=' + '${commonPropertyName}'",
                      update: "populateSWVersion${dataindex}"
                      )};  $("#versionBlock${dataindex}").hide();"/>


<span id="versionBlock${dataindex}">
                test="${value?."${propertyName}"?."${commonPropertyName}"?.id}">
                    <g:select optionKey="id" from="${propertyList}" class="fullBorderBox" name="dummyVal" value="${value?."${propertyName}"?.id}" noSelection="${['null': message(code: 'common.list.select')]}" onclick="populateVersionList(null);" />

            </span>
            %{---pass an dynami id to populate version block pick list----}%
            <span id="populateSWVersion${dataindex}"></span>

1 个答案:

答案 0 :(得分:1)

不需要在html中编写所有JS处理程序。您可以将回调事件移动到JS中的函数。然后做你想做的任何逻辑。

${remoteFunction(
                      controller: 'middlewareData',
                      action: 'populateVersion',
                      params: "'typeId=' + this.value + '&&lookUpProperty=' + '${commonPropertyName}'",
                      update: "populateSWVersion${dataindex}"
                      )};  $("#versionBlock${dataindex}").hide();

将此代码移动到JS函数。从这个回调你可以调用你想要的其他功能。

    // make your server call
    function getData(){
    $.ajax({
     //....
     });
    }

然后只需将此功能连接到on change事件

即可

onchange="getData()"