THIS.VALUE是工作在Firefox,但无法在Internet Explorer? [英] this.value is working on Firefox, but not in Internet Explorer?

查看:113
本文介绍了THIS.VALUE是工作在Firefox,但无法在Internet Explorer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的onChange 事件选择

当我做了一个警报(THIS.VALUE),它的工作在Firefox,但不能在IE浏览器。为什么不呢?

这是在code:

 <选择的onchange =新的Ajax.Updater(销售商,/~project/index.php/folder/fiche',{异步:真,evalScripts:真正的,参数:'平片='+ THIS.VALUE});类=输入ID =平片NAME =平​​片>
  <期权价值=0> Choisir马平片< /选项>
  <期权价值=1> VOUS etes工资和LT; /选项>
  <期权价值=2>三世EMPLOI< /选项>
< /选择>
 

解决方案

我曾在过去与IE浏览器并选择类似的问题。选择物品的价值属性是在IE中的痛苦。通常的解决办法是关心所选择的选项(而不是选择元素),并获得它的文本属性。

我会为此在jQuery来访问选中的文字:

  $(#my_select_item选项:选择)文本()。
 

所以,在原始的JavaScript就应该是这样的:

<$p$p><$c$c>document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].text

<$p$p><$c$c>document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].value

这是要选择+ JS发生在IE浏览器的总体思路。

I have an onChange event on a select.

When I do an alert(this.value), it's working on Firefox, but not on Internet Explorer. Why not?

This is the code:

<select onchange="new Ajax.Updater('fiches', '/~project/index.php/folder/fiche', {asynchronous:true, evalScripts:true, parameters:'fiche=' + this.value});" class="input" id="fiche" name="fiche">
  <option value="0">Choisir ma fiche</option>
  <option value="1">Vous etes salariés</option>
  <option value="2">Sans emploi</option>
</select>

解决方案

I have had similar problems in the past with IE and selects. The value property of select items is a pain in IE. Usually the solution is to care about the selected option (not the select element) and access to its text attribute.

I'll do this in jQuery to access the text selected:

$("#my_select_item option:selected").text()

So, in raw JavaScript it should be something like:

document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].text

or

document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].value

That is the general idea to make selects + JS happen in IE.

这篇关于THIS.VALUE是工作在Firefox,但无法在Internet Explorer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆