Javascript 使用“.append"渲染 HTML- 简单的代码解释 [英] Javascript Rendering HTML with ".append" - Simple Code Explanation
问题描述
谁能解释一下这段代码的每一行是什么意思?我正在尝试将 <script>
调用语句移动到我的 HTML 中的特定位置,但是我的脚本生成的代码总是将它移动到一个特定表的底部,我认为它有一些东西用这段代码来做.我更愿意通过重写此函数来自己定位它,以在 出现在 HTML 中的位置插入代码.
Can Anyone explain what each line of this code means? I'm trying to move the <script>
call statement to a specific position in my HTML but the code generated by my script always moves this to the bottom of one particular table and I think it has something to do with this code. I would prefer to position it myself by rewriting this function to insert the code at the point where the <script>
appears in the HTML.
function initialize(instance) {
_this = instance;
// build html
var realCaller = caller != null? caller:$("body");
var cornerClass = options.showRoundCorner? "ui-corner-all ":"";
realCaller.append("<div id='"+windowId+"' class='window_panel "+cornerClass+options.containerClass+"'></div>");
container = realCaller.children("div#"+windowId);
提前致谢!
推荐答案
你的 标签应该留在原来的位置.移动它无济于事.
Your <script>
tag should be left wherever it was originally. Moving it around will not help.
我假设该页面使用的是 jQuery,但我无法从您发布的内容中确定.
I am assuming the page is using jQuery, but I can't tell for sure from what you've posted.
首先,您需要在要插入 HTML 的页面元素上放置一个 id
属性(即 <div id="your_id_here"></div>
.然后,更改这一行:
First, you need to put an id
attribute on the page element where you want the HTML to be inserted (i.e. <div id="your_id_here"></div>
. Then, change this line:
var realCaller = caller != null? caller:$("body");
为此:
var realCaller = $('#your_id_here');
用您在页面元素上设置的 ID 替换your_id_here".
Replacing "your_id_here" with the ID that you set on the page element.
注意:由于您发布的代码很少,因此很难知道此修复"是否会破坏代码的其他部分....
Note: Since you posted so little of your code, it's hard to know whether this "fix" will break other parts of the code....
这篇关于Javascript 使用“.append"渲染 HTML- 简单的代码解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!