私は、テキストボックスとチェックボックスのチェックを有効にし、チェックボックスをオフにしたときにテキストボックスとボタンの両方を無効にする必要があるという、私のUI上のシナリオを持っています。以下は、私が持っているもののスクリーンショットです:チェックボックスをオンにするとボタンを有効にしますか?
以下私のJSPのコードです:
以下<tr>
<td>
<stripes:checkbox name="locationselect" onclick="handleDisable(document.forms['dealerTransactionForm'].elements['locationselect'],document.forms['dealerTransactionForm'].elements['locationId'])"/>
<stripes:label for="locationId"/>
</td>
<td>
<stripes:text name="locationId" />
<fmt:message var="tooltip" key="/DealerTransactionReport.action.lookUpLocation"/>
<stripes:submit name="lookUpLocation" class="button" title="${tooltip}" style="width: auto"/>
</td>
</tr>
私が書いたhandleDisable
機能である:現在
function handleDisable(checkbox, item) {
if(checkbox.checked == true)
item.disabled = false;
else
item.disabled = true;
}
チェックボックスをオンにするとテキストボックスのみを有効にできます。テキストボックスとボタンの両方を有効にするにはどのような変更を行う必要がありますか。
あなたはボタンの機能に三番目のパラメータに渡す必要があります。チェックボックスとテキストボックスを渡すだけです。しかしボタンはありません。 – user1289451
[チェックボックスがオンの場合、チェックボックスを有効または無効にする方法](http://stackoverflow.com/questions/18110865/how-to-disable-enable-a-button-with-a-checkbox-if) -checked) –
答えはありませんが、 'handleDisable'の最初のパラメータとして' this'を渡すことができます。また、私の意見では、議論のリストはあまりにも漠然としています。代わりに入力の名前を渡すのはどうでしょう。このように: 'handleDisable(this、 'locationId')'。フォームの名前をハードコードする必要があります。または、3番目のパラメータとして渡すこともできます。 'handleDisable( 'dealerTransactionForm'、this、 'locationId')' –