2014-02-14 38 views
0

我已经创建了一个自定义标记,现在我正在尝试获取自定义属性的值,我尝试了很多方法,出于某种原因警报返回undefind ...谢谢你们。自定义标记选择.attr返回undefined

<goladmin:select cssClass="shortSelect" 
      path="textType" 
      items="${textTypeList}" 
      itemValue="id" 
      itemLabel="description" 
      widgetType="widget"        
      onchange="true"             
      multiple="false" /> 

的JavaScript

<script language="javascript" type="text/javascript"> 
$(document).ready(function() { 

    //call to get the widget type 
    getWidgetType();  

    //On select dropdown change 
    $('#textType').change(function(){ 

     var wt = $('#textType').val(); 
     alert("widgetType=" + wt); 


     //call to get the widget type 
     //getWidgetType(); 
    }); 
}); 


function getWidgetType(){ 

    var value = $('#textType').val(); 
    //set hidden textTypeWidget to the selected widget 
    $('#textTypeWidget').val(value); 

    //get the widget type value from the hidden field 
    var widgetType = $('#textTypeWidget').val(); 

    // show and hide the editor based on the widget type 
    if(widgetType == "CKEDITOR") {    
     $('#ckEditorEditor').show(); 
     $('#textAreaEditor').hide(); 

    }else{ 
     $('#ckEditorEditor').hide(); 
     $('#textAreaEditor').show(); 
    } 

} 

生成的HTML

<select id="textType" name="textType" class="shortSelect" onchange="true"><option value="1" selected="selected"></option><option value="2">button label</option><option value="3">title</option><option value="4">error message</option><option value="5">link text</option><option value="6">url</option><option value="7">label</option><option value="8">text</option><option value="9">table title</option><option value="10">help text</option><option value="11">question text</option><option value="12">answer text</option><option value="13">question help text</option><option value="14">glossary</option><option value="15">information mesage</option><option value="16">confirmation message</option><option value="17">system message</option></select> 

生成的HTML设定项目值时小部件....

<select id="textType" name="textType" class="shortSelect" onchange="true"><option value="TEXTAREA" selected="selected"></option><option value="TEXTAREA">button label</option><option value="CKEDITOR">title</option><option value="TEXTAREA">error message</option><option value="TEXTAREA">link text</option><option value="TEXTAREA">url</option><option value="TEXTAREA">label</option><option value="TEXTAREA">text</option><option value="TEXTAREA">table title</option><option value="CKEDITOR">help text</option><option value="CKEDITOR">question text</option><option value="CKEDITOR">answer text</option><option value="TEXTAREA">question help text</option><option value="CKEDITOR">glossary</option><option value="CKEDITOR">information mesage</option><option value="CKEDITOR">confirmation message</option><option value="CKEDITOR">system message</option></select> 
+0

可以共享生成的HTML? –

+0

对不起,我没有明白...谁或什么是#textTypeWidget? –

+0

textTypeWidget将是我将基于textType显示给用户的编辑器的类型......我知道我的问题是什么,我需要为textTypeWidget的自定义标记添加一个新属性,以便让我做到这一点。生成HTML应该基本看起来像这样 Korda

回答

0

尝试使用:的

var wt = $('.shortSelect').attr('widgetType'); 

代替:

var wt = $('#textType').attr('widgetType'); 
+0

尝试过并仍然未定义:( – Korda

+0

@Korda您生成的HTML没有任何“widgetType =”小部件“'? – Felix

+0

耶和我不知道为什么:(大声笑不奇怪它返回undefined :(我做了var wt = $('#textType')。val();并且我得到了值...并且如果我将itemValue更改为小部件我确实得到了小部件类型...不知道最新的东西现在.. – Korda

0

的 '#' 是id选择,你需要设置ID在你的元素:

<goladmin:select 
     id="textType" 
     cssClass="shortSelect" 
     path="textType" 
     items="${textTypeList}" 
     itemValue="id" 
     itemLabel="description" 
     widgetType="widget"        
     onchange="true"             
     multiple="false" /> 

var wt = $('#textType').attr('widgetType'); 
alert("widgetType=" + wt); 
+0

umm howcome $('#textType') .change(function(){works w没有ID?我确实尝试了添加id并仍然一样:( – Korda

+0

oO,你确定吗?rsrs – brunozrk

+0

大声笑相信我,我有警觉(“改变”);每次我改变下拉列表我会得到这个警报:) – Korda

相关问题