我的jQuery脚本创建了一个表单。我需要表单在脚本之前出现:
<script type="text/javascript" src="..."></script>
//the form appears here...
此前一行会显示在各个网站上,因此我无法将其插入/附加到元素$('element')...
,它必须是:$('current script').prepend('...')
我希望用户能够将脚本插入到希望表单出现的位置
我怎样才能做到这一点?
答案 0 :(得分:1)
如果我理解你的问题......
$('script[src="your/path"]').after(element);
其中element是您要插入的内容。
http://api.jquery.com/attribute-equals-selector/
http://api.jquery.com/after/
答案 1 :(得分:0)
通常您正在使用document.write()
来实现这一点(例如,谷歌在插入分页时就这样做了)
答案 2 :(得分:0)
您可以插入带有document.write()
的占位符,并使用jQuery将表单放入palceholder。所以你的脚本看起来像这样:
document.write('<div id="placeholderForForm"></div>");
$('#placeholderForForm').xx(...);
更简单的可能是使用document.write()
插入大型表单。