我试图在 Liferay 中动态创建文本框,如此处所示。
我可以用<input>
tag 做,但不能用<aui:input>
,为什么?
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<html>
<portlet:defineObjects />
<script type="text/javascript">
$(document).ready(function(){
var counter = 2;
$("#addButton").click(function () {
if(counter>10){
alert("Only 10 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
alert();
newTextBoxDiv.html('<aui:input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" />');
alert(newTextBoxDiv.html);
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
});
$("#removeButton").click(function () {
if(counter==1){
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$("#getButtonValue").click(function () {
var msg = '';
for(i=1; i<counter; i++) {
msg += "\n Textbox #" + i + " : " + $('#<portlet:namespace/>textbox' + i).val();
}
alert(msg);
});
});
</script>
<div id='TextBoxesGroup'>
<div id="TextBoxDiv1">
<aui:input type="text" label="TextBox #1" id="textbox1" name="textbox1"></aui:input>
</div>
</div>
<input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>
</body>
</html>