0
通過點擊按鈕「向上」或「向下」,塊div與class = poll_row應更改地點與更早或更晚div class = poll_row並更改+1屬性隱藏字段的值屬性或-1如何使用jQuery交換塊?
有以下功能:
資產/ Java腳本/ poll_items.js
$(function(){
$(document).on('click', '.down_id', function() {
$(this).siblings('.sequence').val(parseFloat($(this).siblings('.sequence').val()) + 1);
$(this).parent().next().children('.sequence').val($(this).parent().next().children('.sequence').val() - 1);
$(this).closest('.poll_row').insertAfter($(this).closest('.poll_row').next());
});
$(document).on('click','.up_id', function() {
$(this).siblings('.sequence').val(parseFloat($(this).siblings('.sequence').val()) -1);
$(this).parent().prev().children('.sequence').val(parseFloat($(this).parent().prev().children('.sequence').val())+ 1);
$(this).closest('.poll_row').insertBefore($(this).closest('.poll_row').prev());
});
點擊該鍵可以改變隱藏標籤的價值。
但是隻有雙擊一個按鈕才能反轉塊。我不明白是什麼原因導致沒有任何反應當我第一次點擊時
錯誤在哪裏?
民調/ edit.html.haml
.................................................
.items-index
= f.simple_fields_for :poll_items do |poll|
= render 'poll_item_fields', f: poll
.................................................
民調/ poll_item_fields.html.haml
.poll_row
.poll_item
= f.input :answer, input_html: { class: 'ctrlenter expanding' }, label: false, placeholder: 'Введите вариант ответа'
= f.hidden_field :sequence, class: 'sequence'
= button_tag 'вверх', type: 'button', class: 'up_id', value: 'вверх'
= button_tag 'вниз', type: 'button', class: 'down_id', value: 'вниз'
- if @poll.editable?(current_user)
= link_to_remove_association "удалить", f, { wrapper_class: 'poll_item' }