javascript - 在 JavaScript 中编写 html bean

标签 javascript html struts javabeans

嘿伙计们, 我正在尝试使用java脚本编写动态html bean 但当我按下按钮时,我不断收到“找不到功能”JS错误.. 这是示例代码

<html>
<html:form action="loginAction.do" >
<head>
    <script type="text/javascript">
        function test(){
            document.getElementById('dd').innerHTML =
                              "<html:text property='pid'/>";
        }
    </script>

</head>
<body>
            <table align="center">
                <tr>
                    <td align="center">
                    <input type="button" value="addprod" onclick="test()"/>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <div id="dd"></div>
                    </td>
                </tr>
            </table>
    </html:form>
</body>
</html>

我不知道

<html:form action="loginAction.do" >

它应该位于哪里 我试图在 <body> 中找到它 但由于写 <html:text property='pid'/> 我得到了一个很大的异常(exception)在 <html:form> 之外的 JavaScript 中 ... 需要你的帮助, 问候,

最佳答案

我认为struts正在尝试解析<html:text />作为脚本中的标签,而不仅仅是 JavaScript 字符串。尝试移动 <html:form action="loginAction.do" >进入 body 和<script> <html:form>内类似于这个 fiddle http://www.jsfiddle.net/pL4Aq/1/

但是,它可以在 fiddle 中工作,因为它只是直接的 HTML...我不认为你想要做的事情会起作用。 <html:text >是一个自定义标签,它在服务器上进行处理,执行一系列操作,然后为您生成 HTML。你永远不会真正看到<html:text>如果您从浏览器查看源代码,即使它位于您的 jsp 中。

您可能想尝试更改 <html:text ><input type="text">标记(在这种情况下,您可以将 <html:form> 移到正文中并将脚本保留在原来的位置)。

关于javascript - 在 JavaScript 中编写 html bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4348776/

相关文章:

javascript - 如何使用 Hapi.js 提供静态 HTML 索引

javascript - destroy_all(删除所选按钮)对某些用户没有响应

HTML 电子邮件无间距

javascript - HTML <a> 标签事件顺序

Struts html html :text does not close input type ="text" tags

Ajax 前提条件失败错误

javascript - 检测页面是否在 iframe 内并获取 iframe id

javascript - 替代 ALLOW_KEYBOARD_INPUT javascript 全屏

python - Beautiful Soup 嵌套标签搜索

validation - 我应该使用什么验证