THIS.VALUE是工作在Firefox,但无法在Internet Explorer?工作、VALUE、THIS、Explorer

2023-09-10 17:59:56 作者:终究敌不过的岁月

我有一个的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< /选项>
< /选择>
 
电脑越来越慢怎么办 ASC10一键提速高达200

解决方案

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

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

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

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

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

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.