将参数从速度传递到 JavaScript

发布于 2024-11-19 17:55:52 字数 1741 浏览 6 评论 0原文

我添加了onfocus和onclick来选择并编写java脚本函数,如下所示。使用velocity ie,.vm 文件来调用javascript 函数。

    <script type="text/javascript">
                function fixA(val){
                    alert(val);                              
                   // document.getElementById(val).style.zIndex="100";
                   val.style.zIndex=300;
                }
                function fixB(val){
                    alert(val);                               
                   // document.getElementById(val).style.zIndex="300";
                      val.style.zIndex=300;
                }

            </script>


#elseif ( $el.type.code == "listbox" )
#if( $errorFields.contains($name) )
    <div class="label selectbox big error"> 
#else
    <div class="label selectbox big" >
#end
    #if ($el.label)
        #if ($el.mandatory)
            <label class="label_content" for="$name">$el.label *</label>
        #else
            <label class="label_content" for="$name">$el.label</label>
        #end
    #end
    <select class="select_styled" id="$name" name="$name" onfocus="fixA($name)" onclick="fixB($name)" >
        #foreach($val in $el.values)
            #set ($sel = "")
            #if ($allInputFields.get($name) == $val)
                #set ($sel = ' selected="selected"')
            #end
            <option$sel onclick="resetIndex()">$val</option>
        #end
    </select>
    <div class="clr">
    </div>
</div>

1)我使用的是IE7,它不能工作,它在FF中工作正常。

2) alert(val) 给出 [object HTMLSelectElement] 的值,但 alert( document.getElementById(val)); 给出 null。我该如何解决它?

I have added onfocus and onclick to select and written java script function as shown below. using velocity i.e., .vm files to invoke javascript function.

    <script type="text/javascript">
                function fixA(val){
                    alert(val);                              
                   // document.getElementById(val).style.zIndex="100";
                   val.style.zIndex=300;
                }
                function fixB(val){
                    alert(val);                               
                   // document.getElementById(val).style.zIndex="300";
                      val.style.zIndex=300;
                }

            </script>


#elseif ( $el.type.code == "listbox" )
#if( $errorFields.contains($name) )
    <div class="label selectbox big error"> 
#else
    <div class="label selectbox big" >
#end
    #if ($el.label)
        #if ($el.mandatory)
            <label class="label_content" for="$name">$el.label *</label>
        #else
            <label class="label_content" for="$name">$el.label</label>
        #end
    #end
    <select class="select_styled" id="$name" name="$name" onfocus="fixA($name)" onclick="fixB($name)" >
        #foreach($val in $el.values)
            #set ($sel = "")
            #if ($allInputFields.get($name) == $val)
                #set ($sel = ' selected="selected"')
            #end
            <option$sel onclick="resetIndex()">$val</option>
        #end
    </select>
    <div class="clr">
    </div>
</div>

1)I am using IE7 and it is not working, it is working fine in FF.

2) alert(val) gives value of [object HTMLSelectElement], but alert( document.getElementById(val)); gives null. how can i solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等风来 2024-11-26 17:55:52

主要错误 您需要引用名称 fixA('$name')

最好传递 this: onfocus="fixA(this)"

function fixA(sel){
  sel.style.zIndex=100; // int, not a string
}

看来您找错了树。

该插件将 DOM 重写为一组 div

,您使用的 jQuery 选择框插件 应该能够实现您想要实现的目标,但由于某些 IE7 特定原因而失败:$container。 css("z-index", "10000");

Main mistake You need to quote the name fixA('$name')

Better to pass this: onfocus="fixA(this)"

function fixA(sel){
  sel.style.zIndex=100; // int, not a string
}

Seems you are barking up the wrong tree.

The plugin rewrites the DOM into a set of divs

And the jQuery selectbox plugin you use is supposed to do just what you are trying to achieve and is failing for some IE7 specific reason: $container.css("z-index", "10000");

调妓 2024-11-26 17:55:52

变量 s 不是 ID,它已经是对元素的引用。

variable s is not an ID, it is already a reference to an element.

妳是的陽光 2024-11-26 17:55:52

如果没有引号,它将传递一个名为 $name 的对象,而不是字符串“$name”。那将为空或未定义。

在 onclick 中用单引号引用“$name”:onclick="fixA('$name')"

Without the quotes, it's passing an object named $name, not the string "$name". That'll be null or undefined.

Quote "$name" in your onclick with single quotes: onclick="fixA('$name')"

謌踐踏愛綪 2024-11-26 17:55:52

像这样改变它:

<select class="select_styled" id="$name" name="$name" 
        onfocus="fixA('$name')" onclick="fixB('$name')">

Change it like so:

<select class="select_styled" id="$name" name="$name" 
        onfocus="fixA('$name')" onclick="fixB('$name')">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文