0

jQueryを使用して、次のことを行います

MyCompaniesInfo = $('input[name^="Companies"]');

そして、コンソールは私にこれを与えます(Firebug):

MyCompaniesInfo


Object[input b1280bf5...73a2a334, input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__IsExist False, input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__Type Company, 29 more...]

0 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__Name.text-box
1 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__phone.text-box
2 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__address.text-box
3 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__street.text-box
4 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__anotherthing.text-box
5 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__another.text-box
6 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__blabla.text-box
7 input#Companies_b1280bf5-102e-4592-a1b1-53e973a2a334__loremipsum.text-box

8 input#Companies_b1280bf52a1b1-53e973a2a334__Name.text-box
9 input#Companies_b1280bf5a1b1-53e973a2a334__phone.text-box
10 input#Companies_b1280bf5a1b1-53e973a2a334__address.text-box
11 input#Companies_b1280bf5a1b1-53e973a2a334__street.text-box
12 input#Companies_b1280bf5a1b1-53e973a2a334__anotherthing.text-box
13 input#Companies_b1280bf5a1b1-53e973a2a334__another.text-box
14 input#Companies_b1280bf5a1b1-53e973a2a334__blabla.text-box
15 input#Companies_b1280bf5a1b1-53e973a2a334__loremipsum.text-box

...。

たとえば、「名前」で終わるすべてのフィールドが必要なので、これを試しました。

$('input[name$="Name"]', MyCompaniesInfo).val('Name');

しかし、それは機能しません。どうすればjqueryで選択を続けることができますMyCompaniesInfo = $('input[name^="Companies"]');か?

4

1 に答える 1

1

問題は、最初のセレクターを使用するときにMyCompaniesInfo = $('input[name^="Companies"]');、要素の配列をに格納することですMyCompaniesInfo

次に、次のように、使用する必要のある要素をフィルタリングする場合filter

$(MyCompaniesInfo).filter('input[name$="Name"]')

次のコードが機能しないのはなぜですか? これは、APIで説明されているように、DOMツリーを介した検索と$('input[name$="Name"]', MyCompaniesInfo)
同じであり、検索のみが行われるためです。$(MyCompaniesInfo).find('input[name$="Name"]')

Given a jQuery object that represents a set of DOM elements, the .find() method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements.

ここでデモを見ることができます。

于 2012-12-11T00:27:33.233 に答える