我有兩個標籤「文本模式」和「Html模式」單選按鈕。如果選擇了文本模式,則只應顯示<h:inputTextarea/>
,並且HTML編輯器的內容必須爲空。如果選擇Html模式,則應顯示<rich:editor/>
,並且文本textarea必須爲空。默認選擇是文本模式。 (即,如果用戶在文本模式下添加文本並導航到HTML模式,我們想展示的未富先清除textarea的:編輯反之亦然)如何清除單選按鈕更改元素的內容
<input id="textMode" type="radio" name="text" value="textMode">Text mode</input>
<input id="htmlMode" type="radio" name="text" value="htmlMode">Html mode</input>
<table id="questionText">
<tr>
<td id="textQuestionField">
<h:inputTextarea value="#{forum.message}" cols="80" rows="3"/>
</td>
<td id="htmlQuestionField">
<rich:editor theme="advanced" useSeamText="true" viewMode="visual" autoResize="true" value="#{forum.message}">
<f:param name="theme_advanced_buttons1" value="newdocument,separator,cut,copy,paste,separator,bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,removeformat,visualaid,separator,sub,sup"/>
<f:param name="theme_advanced_buttons2" value="bullist,numlist,separator,outdent,indent,blockquote,separator,undo,redo,separator,link,unlink,anchor,separator,image,cleanup,help,code,separator,forecolor,backcolor"/>
<f:param name="theme_advanced_buttons3" value="fontselect,fontsizeselect,formatselect,styleselect,separator,charmap"/>
<f:param name="theme_advanced_resizing" value="true"/>
<f:param name="theme_advanced_toolbar_location" value="top" />
<f:param name="theme_advanced_toolbar_align" value="left" />
</rich:editor>
</td>
</tr>
</table>
function textHtmlQuestionHandler(tableId, radioButtonTextId, radioButtonHtmlId, textQuestionId, htmlQuestionId) {
// Text Mode is enabled by default
jQuery(radioButtonTextId).attr('checked', true);
jQuery(tableId).find(htmlQuestionId).hide();
jQuery("input[type='radio']").change(function() {
// Hide HTML question field, if text mode is enabled
if (jQuery(radioButtonTextId).is(':checked')) {
jQuery(tableId).find(textQuestionId).show();
jQuery(tableId).find(htmlQuestionId).hide();
} else if (jQuery(radioButtonHtmlId).is(':checked')) {
// Hide text question field, if HTML mode is enabled
jQuery(tableId).find(htmlQuestionId).show();
jQuery(tableId).find(textQuestionId).hide();
}
});
}
如何實現這一目標?