将参数从速度传递到 JavaScript
我添加了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
主要错误 您需要引用名称 fixA('$name')
最好传递 this: onfocus="fixA(this)"
看来您找错了树。
该插件将 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)"
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");
变量
s
不是 ID,它已经是对元素的引用。variable
s
is not an ID, it is already a reference to an element.如果没有引号,它将传递一个名为 $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')"
像这样改变它:
Change it like so: