我看到一羣人在線報告此問題,但沒有實際的解決方案。我沒有使用AJAX或更新面板,只是在選定索引更改時發佈的下拉菜單。我的HTML是回發後丟失jQuery功能
<div id="myList">
<table id="ctl00_PlaceHolderMain_dlFields" cellspacing="0" border="0" style="border-collapse:collapse;">
<tr>
<td>
<tr>
<td class="ms-formlabel" style="width: 175px; padding-left: 10px">
<span id="ctl00_PlaceHolderMain_dlFields_ctl00_lblDestinationField">Body</span>
</td>
<td class="ms-formbody" style="width: 485px">
<input name="ctl00$PlaceHolderMain$dlFields$ctl00$txtSource" type="text" id="ctl00_PlaceHolderMain_dlFields_ctl00_txtSource" class="ms-input" style="width:230px" />
<select name="ctl00$PlaceHolderMain$dlFields$ctl00$ddlSourceFields" id="ctl00_PlaceHolderMain_dlFields_ctl00_ddlSourceFields" class="ms-input">
<option value="Some Field Name 1">Some Field Name 1</option>
<option value="Some Field Name 2">Some Field Name 2</option>
<option value="Some Field Name 3">Some Field Name 3</option>
<option value="Some Field Name 4">Some Field Name 4</option>
</select>
<a href="#" id="appendSelect">append</a>
</td>
</tr>
</td>
</tr><tr>
<td>
<tr>
<td class="ms-formlabel" style="width: 175px; padding-left: 10px">
<span id="ctl00_PlaceHolderMain_dlFields_ctl01_lblDestinationField">Expires</span>
</td>
<td class="ms-formbody" style="width: 485px">
<input name="ctl00$PlaceHolderMain$dlFields$ctl01$txtSource" type="text" id="ctl00_PlaceHolderMain_dlFields_ctl01_txtSource" class="ms-input" style="width:230px" />
<select name="ctl00$PlaceHolderMain$dlFields$ctl01$ddlSourceFields" id="ctl00_PlaceHolderMain_dlFields_ctl01_ddlSourceFields" class="ms-input">
<option value="Some Field Name 1">Some Field Name 1</option>
<option value="Some Field Name 2">Some Field Name 2</option>
<option value="Some Field Name 3">Some Field Name 3</option>
<option value="Some Field Name 4">Some Field Name 4</option>
</select>
<a href="#" id="appendSelect">append</a>
</td>
</tr>
</td>
</tr><tr>
<td>
<tr>
<td class="ms-formlabel" style="width: 175px; padding-left: 10px">
<span id="ctl00_PlaceHolderMain_dlFields_ctl02_lblDestinationField">Title</span>
</td>
<td class="ms-formbody" style="width: 485px">
<input name="ctl00$PlaceHolderMain$dlFields$ctl02$txtSource" type="text" id="ctl00_PlaceHolderMain_dlFields_ctl02_txtSource" class="ms-input" style="width:230px" />
<select name="ctl00$PlaceHolderMain$dlFields$ctl02$ddlSourceFields" id="ctl00_PlaceHolderMain_dlFields_ctl02_ddlSourceFields" class="ms-input">
<option value="Some Field Name 1">Some Field Name 1</option>
<option value="Some Field Name 2">Some Field Name 2</option>
<option value="Some Field Name 3">Some Field Name 3</option>
<option value="Some Field Name 4">Some Field Name 4</option>
</select>
<a href="#" id="appendSelect">append</a>
</td>
</tr>
</td>
</tr>
</table></div>
上面的Div標記是靜態的,並且該表是從DataList對象生成的。在回傳數據列表重新加載使用新的數據集,例如
<div id="myList">
<table id="ctl00_PlaceHolderMain_dlFields" cellspacing="0" border="0" style="border-collapse:collapse;">
<tr>
<td>
<tr>
<td class="ms-formlabel" style="width: 175px; padding-left: 10px">
<span id="ctl00_PlaceHolderMain_dlFields_ctl00_lblDestinationField">Notes</span>
</td>
<td class="ms-formbody" style="width: 485px">
<input name="ctl00$PlaceHolderMain$dlFields$ctl00$txtSource" type="text" id="ctl00_PlaceHolderMain_dlFields_ctl00_txtSource" class="ms-input" style="width:230px" />
<select name="ctl00$PlaceHolderMain$dlFields$ctl00$ddlSourceFields" id="ctl00_PlaceHolderMain_dlFields_ctl00_ddlSourceFields" class="ms-input">
<option value="Some Field Name 1">Some Field Name 1</option>
<option value="Some Field Name 2">Some Field Name 2</option>
<option value="Some Field Name 3">Some Field Name 3</option>
<option value="Some Field Name 4">Some Field Name 4</option>
</select>
<a href="#" id="appendSelect">append</a>
</td>
</tr>
</td>
</tr><tr>
<td>
<tr>
<td class="ms-formlabel" style="width: 175px; padding-left: 10px">
<span id="ctl00_PlaceHolderMain_dlFields_ctl01_lblDestinationField">URL</span>
</td>
<td class="ms-formbody" style="width: 485px">
<input name="ctl00$PlaceHolderMain$dlFields$ctl01$txtSource" type="text" id="ctl00_PlaceHolderMain_dlFields_ctl01_txtSource" class="ms-input" style="width:230px" />
<select name="ctl00$PlaceHolderMain$dlFields$ctl01$ddlSourceFields" id="ctl00_PlaceHolderMain_dlFields_ctl01_ddlSourceFields" class="ms-input">
<option value="Some Field Name 1">Some Field Name 1</option>
<option value="Some Field Name 2">Some Field Name 2</option>
<option value="Some Field Name 3">Some Field Name 3</option>
<option value="Some Field Name 4">Some Field Name 4</option>
</select>
<a href="#" id="appendSelect">append</a>
</td>
</tr>
</td>
</tr>
</table></div>
回發,並在DataList重新加載後,我的JQuery不工作了。沒有錯誤,沒有。我沒有看到任何應該導致這種情況的HTML中對象的實際更改。我該如何解決?任何變通辦法或bandaides我可以申請?我的JQuery低於
<script type='text/javascript'>
$(document).ready(function() {
$('#myList a').live("click", function() {
var $selectValue = $(this).siblings('select').val();
var $thatInput = $(this).siblings('input');
var val = $thatInput.val() + ' |[' + $selectValue + ']|';
$thatInput.val(jQuery.trim(val));
})
});
</script>
謝謝!!
你有沒有試過用Firebug調試它,看看jQuery是否正確加載,以及你的準備工作是否正在執行? – Raphael 2011-02-18 15:24:27