0

残念ながら、私は javascript/jQuery にあまり詳しくありません。ドロップダウンのあるフォームがあります。私がする必要があるのは、ドロップダウンの選択に応じてテキスト フィールドに入力することです。ドロップダウンの最初の声は「その他」であるため、テキストフィールドは書き込み可能でなければならず、2番目から自動的に値を割り当ててテキストフィールドを無効にしたいと考えています。

ドロップダウンの値はデータベースに保存されるため、オプションの名前のままにしておく必要があります。

Googleでいくつかの解決策を見つけましたが、どれも私のニーズに合っていません...誰かが私を助けてくれることを願っています.

4

2 に答える 2

2

To create the functionality you're looking for, there are a few basic things you'll need to learn.

jQuery Selectors

First, if you aren't already familiar with jQuery's selector syntax, learn about it here.

The .change() Event

Next, you'll need to know how to bind to the dropdown menu's .change event. One way to do this is $('#dropdownId').change(function() { ... });, which is just a shortcut for $('#dropdownId').on('change', function() { ... }); . Within the callback functions, you can access the dropdown element with this and as a result, the jQuery object with $(this).

We can then grab the dropdown's value with $(this).val() and use some basic logic to enable/disable the textbox and set its value.

Enabling/Disabling the textbox

In order to enable/disable the textbox, you can use: $('#txt').removeAttr('disabled');and$('#txt').attr('disabled', 'true');` respectively.

Example
I've combined all of these for you in an example fiddle to show you how you can put these together in this jsFiddle. Let me know if you have any questions about how it works :)

于 2013-07-31T10:56:01.923 に答える