2012-03-08 113 views
0

在我的網頁我有單選按鈕...如何獲得jquery的星星id值?

<div class="stars-wrapper1">  
    <input type="radio" name="newrate" value="1" title="VeryPoor" @Html.Raw((Model.review == 1?"checked=\"checked\"":"")) />       
    <input type="radio" name="newrate" value="2" title="Poor" @Html.Raw((Model.review == 2?"checked=\"checked\"":"")) />  
    <input type="radio" name="newrate" value="3" title="Average" @Html.Raw((Model.review == 3?"checked=\"checked\"":"")) /> 
    <input type="radio" name="newrate" value="4" title="Good" @Html.Raw((Model.review == 4?"checked=\"checked\"":"")) /> 
    <input type="radio" name="newrate" value="5" title="Excellent"@Html.Raw((Model.review == 5?"checked=\"checked\"":"")) />  
    <input type="hidden" name="rate" value="@Model.ThePhoto.ID" disabled="disabled">      
</div> 

他們是單選按鈕,當我使用功能的明星,他們變成這樣..

<div class="stars-wrapper1">  
    <input type="hidden" name="rate" value="41" disabled="disabled">      
     <div class="ui-stars-star ui-stars-star-on ui-stars-star-disabled"> 
      <a title="">1</a></div> 
     <div class="ui-stars-star ui-stars-star-on ui-stars-star-disabled"> 
      <a title="">2</a></div> 
     <div class="ui-stars-star ui-stars-star-on ui-stars-star-disabled"> 
      <a title="">3</a></div> 
     <div class="ui-stars-star ui-stars-star-disabled"> 
      <a title="">4</a></div> 
     <div class="ui-stars-star ui-stars-star-disabled"> 
      <a title="">5</a> 
     </div> 
     <input type="hidden" name="newrate" value="0" disabled="disabled"> 
</div> 

當我點擊一個明星我隱藏的價值,所以我可以保存到我的分數這是這張照片收到的評級,但我不能得到'這個'隱藏的價值,我得到41阿爾時間第一張照片ID,有幾個這些明星在頁面上與不同的隱藏ID

jquery:

$(document).ready(function() { 
    $(".stars-wrapper1").stars({ 
     oneVoteOnly: true 
    }); 
    $('.stars-wrapper1 a ').click(function() { 
     alert($('input:hidden[name$=rate]').val()); 
    }); 
}); 

有許多不同的圖片,這些明星在一個頁面上,所以相對的IM如何試圖找出什麼樣的形象在用戶評價。

這是我得到的恆星形成... Star Rating Plugin

+0

什麼是.stars()...這是來自某種插件...? – 2012-03-08 10:18:59

+1

你可以鏈接到明星插件嗎?它似乎不太可能會刪除輸入框,因爲它們仍然需要存儲該值。 – 2012-03-08 10:19:44

回答

1

的值存儲在一個隱藏的輸入。你可以嘗試這樣的:

$('.stars-wrapper1 a ').click(function() { 
    alert($('input:hidden', this).val()); 
}); 

爲了更加精確,輸入的名字似乎噸,速度結束了,所以你也可以嘗試

$('.stars-wrapper1 a ').click(function() { 
    alert($('input:hidden[name$=rate]', this).val()); 
}); 
+0

我得到警報但未定義兩種方式 – Beginner 2012-03-08 10:37:43

+0

@Beginner你可以在jsfiddle上發佈你的標記的例子嗎? – 2012-03-08 10:41:17

+0

嗯它的難度與CSS js和圖像的數量 – Beginner 2012-03-08 10:49:02

0

的例子他們的頁面上創建了名稱=「速度」,存儲選擇的值的隱藏輸入。

所以,你應該能夠得到這樣的價值:

$('.stars-wrapper1 a ').click(function() { 
    var result = $('input[name="rate"]').val(); 
    alert(result); 
}); 
+0

我認爲隱藏字段的名稱以rate結尾。此外,我會使用上下文來限制搜索,否則你的代碼會中斷,如果該插件應用在頁面上的更多字段 – 2012-03-08 10:35:04

1

,如果你想在所有的隱藏的字段刪除禁用讓星速度,你可以做以下伎倆

$(".stars-wrapper1").stars({ 
     oneVoteOnly: true, 
     callback: function(ui, type, value) 
       { 
        $(':hidden').removeAttr('disabled') 
       } 
    }); 

它會從所有隱藏的字段刪除禁用

1

我不確定你有多遠與這個星級評分系統,我實際上正在實施另一個現在使用無線電進行輸入的權利。我訪問了您關聯的網站,但我沒有看到任何有關星級評分的示例。我只看到下拉菜單和實際的單選按鈕。

我還注意到,該網站表示,它不能與沒有補丁的jQuery 1.6一起工作,所以我猜想新版本的jQuery也不支持。

我使用的是相當不錯的,雖然我一直在努力與一些jQuery保存收視率數據庫,並讀回表中。它沒有內置數據庫支持。http://www.fyneworks.com/jquery/star-rating/

這個看起來非常好,http://rateit.codeplex.com/releases/view/55958,因爲它使用範圍而不是無線電,看起來更健壯,並且支持jQuery 1.6到1-7.2。我可以切換到這個,但我剛剛完成了與其他數據庫工作。

我知道這並不回答你的問題,但你選擇的系統看起來不支持並且沒有被更新,所以如果你沒有花費很多時間,你可能會想要切換。