简体   繁体   English

无法生成新XHTML内容的Javascript

[英]Javascript to generate new XHTML content not working

I've been scratching at my head with this for a few days now and I cannot find any solution to this online or even with a professor. 几天来,我一直在脑海中摸索,甚至在网上甚至没有教授的情况下,我都找不到任何解决方案。

I'm working on a system that requires some pages to be capable of dynamically generating new HTML content whilst running (JSF web project running on glassfish4 server) I've found some resources on how to do this but it only worked when running on a standard HTML page. 我正在使用一个系统,该系统要求某些页面能够在运行时动态生成新的HTML内容(在glassfish4服务器上运行的JSF Web项目),我已经找到了一些有关如何执行此操作的资源,但只有在标准HTML页面。 When I convert it to the XHTML standard the function no longer generates anything (although it is still being called, the alert box confirmed that). 当我将其转换为XHTML标准时,该函数不再生成任何东西(尽管它仍在被调用,但警告框确认了这一点)。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=ISO-8859-1"></meta>
<title>Insert title here</title>
</head>
<body>
    <SCRIPT type="text/javascript">
        function addQuestion() {
            alert('yay');
            var exam = document.getElementById('divarea');
            var temp = document.createElementNS('h', 'button');
            temp.setAttribute('value', 'child');
            exam.appendChild(temp);
        }
    </SCRIPT>
    <div id="divarea">
    </div>
    <h:commandButton value="create new stuff" onclick="addQuestion()"/>
</body>
</html>

If anyone can shed some light on this issue it'd be greatly appreciated. 如果有人可以阐明这个问题,将不胜感激。

PS Here are the resources I've been using to attempt troubleshooting. PS这是我一直在尝试进行故障排除的资源。

Converting javascript to work with XHTML 转换javascript以使用XHTML

Creating elements dynamically using javascript 使用javascript动态创建元素

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html   xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html">
        <head>
        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=ISO-8859-1"></meta>
        <title>Insert title here</title>
        </head>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <body>
            <SCRIPT type="text/javascript">
                function addQuestion() {


                    var oldcon=$("#divarea").html();
                    var newcon='<button>child</button>';
                    var updcon=oldcon+newcon
                    console.log(newcon);
                    $("#divarea").html(updcon);
                }
            </SCRIPT>
            <div id="divarea">
            </div>
            <button onclick="addQuestion()"/>dff</button>
        </body>
        </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM