如何使用<脚本src="">在页面中插入表单


how to use <script src=""> to insert a form in page

我有这个脚本

    <script type="text/javascript" src="http://localhost/wordpress/wp-content/themes/formsaz/export.php?id=74459533"></script>

我想把它粘贴到我想要的地方,它为我加载了一个表单。export.php中的代码如下:

    <script type="text/javascript">
    function getQuery(name){
    if(name=(new RegExp('[?&amp;]'+encodeURIComponent(name)+'=([^&amp;]*)')).exec(location.search))
    return decodeURIComponent(name[1]);
    }
    var id = getQuery("id");
    document.write("<div style=''width:100%; margin:0px auto''><iframe src='http://localhost/wordpress/wp-content/themes/formsaz/formexport.php?id=" + id + "' scrolling='no' frameborder='0' hspace='0' width='100%' height='100%'></iframe></div>");
    </script>

从数据库获取id并查找数据,然后将创建的数据返回到粘贴第一个脚本的页面。但这行不通!我该怎么做,有什么建议吗?

您可以动态添加脚本(因为您的export.php返回一个javascript):

var jsElm = document.createElement("script");
jsElm.type = "application/javascript";
jsElm.src = "http://localhost/wordpress/wp-content/themes/formsaz/export.php?id=74459533";
document.body.appendChild(jsElm);

或者添加iframe:

var iframe = document.createElement('iframe');
iframe.style.display = "none";
iframe.src = "http://localhost/wordpress/wp-content/themes/formsaz/export.php?id=74459533";
document.body.appendChild(iframe);

当脚本返回数据时,如果可能的话,还应该考虑调用ajax