JS函数隐藏元素值

JS function hidden element value

本文关键字:元素 隐藏 函数 JS      更新时间:2023-09-26

我有一个隐藏元素:

<input id="enableStat" type="hidden" value="<!--#echo var="enableStat"-->" />

我使用这个变量来标记是否启用或禁用了某些feild。

在JS中:

    if(somecondition==false) 
    {
        document.getElementById('enableStat').value = 0;
        //some other statements
    }  
    else
    {
        document.getElementById('enableStat').value = 1;
        //some other statements
    } 

然后我在我的CGI:中检查这个变体

SSPEC_RESOURCE_ROOTVAR("enableStat", sEnable, PTR16, "%s"),       
static char sEnable[2];
if(!strncmp(sEnable, "1", 1))
     //do something

现在,我看到的是,无论怎样,senable中的值总是1。JS中的if-else语句执行正确。

在这里添加以下语句:

document.getElementById('enableStat').value = 0; 
document.getElementById('enableStat').value = 1;

如果我把我的问题说得更清楚:我想在JS中创建一个可以在CGI中使用的变量/元素。我该怎么做。在上面的代码中,似乎有一些语法错误或变量名等。

如果您使用C/C++进行编码,那么您应该使用strncmp比较字符串。strncpy复制字符串并返回目的地的地址,这是一个地址,因此不会为0,因此总是计算为true。。。