小编ilg*_*aar的帖子

如何找出在JavaScript中调用函数的位置?

是否有可能找出调用函数的位置?如果是,那么如果从全局范围调用函数,从另一个函数,或者可能从浏览器控制台调用,如何检测?

看一下下面的例子:

<script>
    function myFunc1() {
        // some code
        myFunc2(); // I was called from myFunc1()
    }
    function myFunc2() {
        var callerName = new String;
        callerName = arguments.callee.caller.name;
        // some code
        alert('I was called from ' + callerName + ' function');
    }
    myFunc2(); // I was called from global scope
</script>
Run Code Online (Sandbox Code Playgroud)

我知道callerName = arguments.callee.caller.name;上面例子中的这一行会给我调用函数的名字.但我不知道如何检测是否从全局范围调用函数.例如,如果我更改myFunc2()并添加一个if else语句来检查是否arguments.callee.caller.name返回一个undefined值,知道这将发生,当从全局范围调用一个函数时:

myFunc2() {
var callerName …
Run Code Online (Sandbox Code Playgroud)

javascript function call

20
推荐指数
2
解决办法
9944
查看次数

如何将网页加载到&lt;div&gt;元素中?

我是Java语言的新手,我有一个关于将网页加载到网站上的div元素(“ content-window”)中的问题。我想在该div中打开一个网页,在这种情况下为http://www.fdsa.com?ID=1。我必须编写以下行才能选择div元素。

var sidediv = document.getElementById('content-window');
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何将网页加载到此div中吗?我已经尝试了很多(但是我当然失败了)。例如,以下行将不起作用:

sidediv.location.assign = "http://www.fdsa.com?ID=1";
Run Code Online (Sandbox Code Playgroud)

提前致谢!

html javascript

3
推荐指数
1
解决办法
2468
查看次数

为什么下面的汇编代码没有打印出新行 (0xa) 字符?

在下面的代码中,NASM 按预期运行所有内容,除了在末尾打印一个换行符。可能是什么原因?

%define sys_write       0x2000004           ; system call number for write
%define sys_read        0x2000003           ; system call number for read
%define sys_exit        0x2000001           ; system call number for exit
%define std_out         0x1                 ; file descriptor number for standard output
%define std_in          0x2                 ; file descriptor number for standard input
%define new_line        0xa                 ; a new line character
%define current_address $                   ; address of current location

; a macro to implement the write system call and write
; a string into …
Run Code Online (Sandbox Code Playgroud)

macos assembly x86-64 nasm

2
推荐指数
1
解决办法
1971
查看次数

为什么即使使用 f 后缀,gcc 也会将浮点文字转换为 double,但 clang 似乎不会?

考虑 C Primer Plus 中的以下代码:

#include <stdio.h>

int main()
{
    float f = 7.0f;
    float g = 8.0f;

    printf("%d %d\n", f, g);        // wrong kind of values

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用 clang 编译器会产生以下输出,这是预期的结果。编译器正确地抱怨分配给错误格式说明符的浮点类型参数:

~$ clang badcount.c -o badcount
badcount.c:11:23: warning: format specifies type 'int' but the argument has type 'float' [-Wformat]
printf("%d %d\n", f, g);        // wrong kind of values
        ~~        ^
        %f
badcount.c:11:26: warning: format specifies type 'int' but the argument has type 'float' [-Wformat]
printf("%d %d\n", f, g); …
Run Code Online (Sandbox Code Playgroud)

c gcc clang

2
推荐指数
1
解决办法
958
查看次数

如何隐藏CKEditor

我在同一页面中有两个 CKEditor。我怎样才能隐藏其中之一?

我试图将 textarea 显示和可见性更改为隐藏,但它不起作用。

$("textarea[name=icerik]").css("visibility", "hidden");
$("textarea[name=enicerik]").css("visibility", "visible");
Run Code Online (Sandbox Code Playgroud)

以下是最初的 CKEditors:

  CKEDITOR.replace( 'icerik' );
  CKEDITOR.replace( 'enicerik' );
Run Code Online (Sandbox Code Playgroud)

javascript css php jquery ckeditor

1
推荐指数
1
解决办法
3206
查看次数

在JavaScript中,在未附加到DOM树的函数内创建的节点是否会使空间混乱?

我习惯于在顶部块中声明范围中的每个变量以获得代码可读性.我怀疑函数范围内未添加到文档正文的节点会使空间混乱,并降低性能.他们会怎么样?一般而言,在函数范围内创建的变量会发生什么?执行功能后它们会被销毁吗?我是否需要担心释放内存?在一个范围的最顶层块声明变量是一个好习惯,还是只在需要时或在某些条件为真时才在现场声明变量?这有助于提高运行时性能吗?

假设这样的函数:

function myfunc() {
    var someNode = document.createElement('div');
    if(someCondition) { // add the node only if some condition is true
        document.body.appendChild(someNode);
    }
Run Code Online (Sandbox Code Playgroud)

VS这样的功能:

function myfunc() {
    if(someCondition) { // create and add the node only if some condition is true
        var someNode = document.createElement('div');
        document.body.appendChild(someNode);
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript dom scope memory-management nodes

0
推荐指数
1
解决办法
39
查看次数

如何检查事件是否绑定到元素,以防止重复绑定?

我有一个函数,基本上创建一个覆盖整个页面的叠加div元素.它还将resize事件绑定到窗口,因此每当调整窗口大小时,叠加层也会更改其大小:

function stdOverlay() {
    var overlay = $('<div />').css({width : $(window).width(), height : $(window).height()});
    var overlayResize =
    function() {
        $(overlay).css({width : $(window).width(), height : $(window).height()});
    };
    $('body').append(overlay);
    $(window).resize(overlayResize);
    //... other codes,  like remove overlay and unbind the events
    //$('div.stdgui-overlay').unbind('resize', overlayResize);
}
Run Code Online (Sandbox Code Playgroud)

每次调用该函数时,如果没有,则添加一个叠加层,并将resize事件绑定到窗口.当它应该删除重叠事件时,它也会取消绑定事件.如果overlayResize方法绑定到window元素,如何防止重复绑定?就像是:

    if(overlyResize is not bound to window)
        $(window).resize(overlayResize);
    else
        //do something else or do nothing;
Run Code Online (Sandbox Code Playgroud)

jquery events bind

0
推荐指数
1
解决办法
2311
查看次数

标签 统计

javascript ×4

jquery ×2

assembly ×1

bind ×1

c ×1

call ×1

ckeditor ×1

clang ×1

css ×1

dom ×1

events ×1

function ×1

gcc ×1

html ×1

macos ×1

memory-management ×1

nasm ×1

nodes ×1

php ×1

scope ×1

x86-64 ×1