我是JQuery,Ajax,JavaScript的新手
我遇到了JQuery star-rating-plugin的问题。我在一些页面中使用它并且它工作得很好。但是,当我在Ajax页面中使用时,它的行为并不相同。
重新加载页面时,不再显示任何内容。输入是隐藏的,就像之前一样,但div不会出现。
页面加载时我有这段代码:
<td class="rowstyle0" width="30%" align="left">
<a onclick="javascript:abrirConsultaNova('/projectManager/projectManager/atividade.do?method=consultar&id=219', 'Consultar 219');" href="#219">
<span class="star-rating-control">
<div class="rating-cancel" style="display: none;">
<a title="Cancel Rating"/>
</div>
<div id="avaliacao1_219" class="star-rating rater-0 star {split:2} star-rating-applied star-rating-readonly star-rating-on" style="width: 8px;">
<a title="1" style="margin-left: 0px;">1</a>
</div>
<div id="avaliacao2_219" class="star-rating rater-0 star {split:2} star-rating-applied star-rating-readonly star-rating-on" style="width: 8px;">
</div>
<div id="avaliacao3_219" class="star-rating rater-0 star {split:2} star-rating-applied star-rating-readonly star-rating-on" style="width: 8px;">
</div>
<div id="avaliacao4_219" class="star-rating rater-0 star {split:2} star-rating-applied star-rating-readonly star-rating-on" style="width: 8px;">
</div>
</span>
<input id="avaliacao1_219" class="star {split:2} star-rating-applied star-rating-readonly" type="radio" disabled="disabled" value="1" name="avaliacao219" style="display: none;"/>
<input id="avaliacao2_219" class="star {split:2} star-rating-applied star-rating-readonly" type="radio" disabled="disabled" value="2" name="avaliacao219" style="display: none;"/>
<input id="avaliacao3_219" class="star {split:2} star-rating-applied star-rating-readonly" type="radio" disabled="disabled" value="3" name="avaliacao219" style="display: none;"/>
<input id="avaliacao4_219" class="star {split:2} star-rating-applied star-rating-readonly" type="radio" disabled="disabled" value="4" name="avaliacao219" style="display: none;"/>
</a>
</td>
这是动态重新加载页面时的代码:
<td class="rowstyle0" width="30%" align="left">
<a onclick="javascript:abrirConsultaNova('/projectManager/projectManager/atividade.do?method=consultar&id=219', 'Consultar 219');" href="#219">
<input id="avaliacao1_219" class="star {split:2} star-rating-applied" type="radio" disabled="disabled" value="1" name="avaliacao219" style="display: none;"/>
<input id="avaliacao2_219" class="star {split:2} star-rating-applied" type="radio" disabled="disabled" value="2" name="avaliacao219" style="display: none;"/>
<input id="avaliacao3_219" class="star {split:2} star-rating-applied" type="radio" disabled="disabled" value="3" name="avaliacao219" style="display: none;"/>
<input id="avaliacao4_219" class="star {split:2} star-rating-applied" type="radio" disabled="disabled" value="4" name="avaliacao219" style="display: none;"/>
</a>
</td>
我怎样才能让div出现在帖子上?
答案 0 :(得分:3)
我遇到了Ajax场景中的问题。只出现了单选按钮。我只是在加载内容后挂钩事件。
$('input[type="radio"].star').rating(); // Hook the events.
可以通过以下声明启用明星。
$('input[type="radio"].star').rating('enable');
答案 1 :(得分:0)
据推测,您正在将事件附加到#star-rating-control。如果您通过AJAX重建DOM,您的事件将会丢失。在AJAX事件之后,您需要重新附加它们。