Home > Web Front-end > JS Tutorial > Solution to click unresponsive and option unresponsive in ie8 mode

Solution to click unresponsive and option unresponsive in ie8 mode

PHPz
Release: 2018-09-30 15:07:12
Original
1673 people have browsed it

Click the option in the select and assign it to the input above, which is written directly with jQuery. The problem is that when it is opened in IE8, nothing happens when clicking the option.

The effect achieved is more common. Click the option in the select and assign it to the input above. It is written directly with jQuery:

$("#cardNoList option").click(function(){
$("#card").attr("value","").attr("value",this.value); 
})
Copy after login

There is a strange thing. Since the users basically use domestic dual-core browsers such as 360 Browser, with the addition of native Eclipse, the chrome kernel is used for parsing. When placed in the test environment, it becomes the IE8 standard for parsing.

Now here comes the question, learn to dig...well, no!

When opening it with IE8, nothing happens when clicking the option.

I tried adding alert:

$("#cardNoList option").click(function(){
alert("111");
$("#card").attr("value","").attr("value",this.value);
alert("222"); 
})
Copy after login

click was not called at all.

At first, I thought it was a compatibility issue with jQuery's click event under IE8, but jQuery has encapsulated the compatibility and is widely used, so it shouldn't happen to me alone.

Later I thought that maybe the click was not added to the option in IE8. I changed it and added the click to the select. Now, IE8, Firefox, and Chrome can all assign values ​​to the input smoothly.

$("#cardNoList").click(function(){
$("#card").attr("value","").attr("value",this.value);
})
Copy after login

After searching on Baidu, it seems that "as we all know, in IE, the select option does not support onclick events" o(╯□╰)o 

After being reminded, it was changed to:

$("#cardNoList").click(function(){
$("#card").val(this.value);
}
Copy after login

The above is the entire content of this chapter. For more related tutorials, please visit jQuery Video Tutorial!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template