我已经创建了一个自定义标记,现在我正在尝试获取自定义属性的值,我尝试了很多方法,并且由于某种原因,警报返回undefind ...谢谢大家。
<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>
将itemValue设置为widget时生成的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 :(得分:0)
尝试使用:
var wt = $('.shortSelect').attr('widgetType');
而不是:
var wt = $('#textType').attr('widgetType');
答案 1 :(得分: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);