0

これはjQueryで可能ですか?

$(elem).('.class').html("new data");

このクラスを持つ要素が複数あるため、現在の要素のクラスの HTML を変更する必要があります。その特定の要素のクラスの HTML のみを変更したい。私は.parent()最も近い子供たちを使用しようとしましたが、役に立ちませんでした。

関数は、tr 内にある td 内にある select タグによって呼び出され、変更したいデータは次の tr にあるため、次のようになります。

<tr>
    <td>select</td>
    <td></td>
    <td></td>
</tr>
<tr>the td's which htmls i want to change</tr>

また<tr>、選択を保持すると複数回追加できるため、パーツが複数選択されることに注意してください$(elem)。また、選択を保持する新しい tr が追加されるたびに、td を保持する tr も追加されるため、サンプルの HTML コードを次に示します。

生成された HTML コード:

  <tr class="action-row">
 <td valign="top">CRM Action:&nbsp;&nbsp;&nbsp;</td>
      <td valign="top"><select name="crm_action[]">
 <option value="add">Add to Group</option>
 <option value="transfer">Transfer to Group</option>
 </select>
 </td>
 <td valign="top">Action:&nbsp;&nbsp;&nbsp;</td>
 <td valign="top">
 <select name="funnel_type[]" class="funnel-type" onchange="type_switch(this)">
 options to determine what to display in this tr onchange
 </select>
 </td>
 <td>
 <img src="somewhere/action_delete.png" title="Delete" onclick="delete_row(this)"     style="cursor: pointer;"></td>
 </tr>
 //this part should have been inside the above tr as you can see it the php code above
 <tr class="actionrow odd">
 <td class="type-label" valign="top"></td>
 <td class="type-selection" valign="top"></td>
 <td class="type-button" valign="top" align="right" colspan="2"></td>
 </tr>
 //end              
 <tr class="action-row">
 <td valign="top">CRM Action:&nbsp;&nbsp;&nbsp;</td>
 <td valign="top">
 <select name="crm_action[]"><option value="add">Add to Group</option>
 <option value="transfer">Transfer to Group</option>
 </select>
 </td>
 <td valign="top">Action:&nbsp;&nbsp;&nbsp;</td>
 <td valign="top">
 <select name="funnel_type[]" class="funnel-type" onchange="type_switch(this)">
 another options
 </select>
 </td>
 <td>
 <img src="somewhere/action_delete.png" title="Delete" onclick="delete_row(this)"      style="cursor: pointer;">
 </td>
      </tr>
 <tr class="actionrow odd">
 <td class="type-label" valign="top"></td>
 <td class="type-selection" valign="top"></td>
 <td class="type-button" valign="top" align="right" colspan="2"></td>
 </tr>
4

3 に答える 3

2

お探しfindですか?

$(elem).find('.class').html("new data");

childrenfind「葉」に達するまで掘りながら1レベル掘ります。

于 2013-04-24T21:37:30.850 に答える
0

elem が変数かどうかによって異なります。

 $('elem.class').html("new data");

また

 $(elem).find('.class').html("new data");
于 2013-04-24T21:38:42.357 に答える
0

これを行うには、要素を選択します

$("div") // Can be whatever you want

次に、CSS の場合と同様にクラスを追加します

$("div.class")

最後に、要素のhtml()またはメソッドを呼び出しますtext()

$("div.class").html("new data")

フィドル

于 2013-04-24T21:39:09.243 に答える