如何将实际值转换为隐藏字段

时间:2014-06-24 16:11:58

标签: javascript jquery jquery-ui jquery-plugins

我正在使用Iconselect,我想问一下如何将实际值和/或选定值传输到隐藏字段中 - 我无法找到解决方案:(

<input type="hidden" id="recommandation" name="recommandation" value="" />
...
<script>
 var iconSelect;
 window.onload = function(){
    iconSelect = new IconSelect("my-icon-select", 
        {'selectedIconWidth':24,
        'selectedIconHeight':24,
        'selectedBoxPadding':1,
        'iconsWidth':20,
        'iconsHeight':20,
        'boxIconSpace':1,
        'vectoralIconNumber':4,
        'horizontalIconNumber':4});
    var icons = [];
    icons.push({'iconFilePath':'/images/sampledata/eval-1.jpg', 'iconValue':'1'});
    icons.push({'iconFilePath':'/images/sampledata/eval-2.jpg', 'iconValue':'2'});
    icons.push({'iconFilePath':'/images/sampledata/eval-3.jpg', 'iconValue':'3'});
    iconSelect.refresh(icons);
 };
</script>

非常感谢

3 个答案:

答案 0 :(得分:2)

$("id-of-selector").on('blur', function(){
    $('#recommandation').val = this.val;
});

var element =  document.getElementById('id-of-selector')
element.addEventListener('blur', function(e){
    document.getElementById('recommandation').value = element.value;
});

答案 1 :(得分:1)

快速浏览一下IconSelect,看起来你可以这样做:

$('#my-icon-select').on('changed', function(){
    $('#recommandation').val(iconSelect.getSelectedValue());
});

答案 2 :(得分:0)

我不知道iconselect从未使用过它,但是用jquery操纵值如果隐藏它并不重要看看:

http://api.jquery.com/val/