ie下获取不到textarea的焦点_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:50:49
Original
1281 people have browsed it

<html lang="en"><head>	<meta charset="UTF-8">	<title>Document</title></head><body>	<textarea name="" id="" cols="30" rows="10" readOnly=true></textarea>	<script src="jquery-1.9.1.js"></script>	<script type="text/javascript">			$(function(){ 				$('textarea').on('click',function(){ 						$(this).attr('readOnly',false);						this.focus();				 })			});	</script></body></html>
Copy after login


各位大牛  我这边想要的效果是单击textarea后就能够获取焦点 并且直接输入 ,这个代码在ff和chrome下面都可以 但 是在ie下面必须得点击两次
我该怎么解决 ··真心求助


回复讨论(解决方案)

允许输入的话就用css模拟readOnly样式,聚焦的时候去掉这个css

允许输入的话就用css模拟readOnly样式,聚焦的时候去掉这个css

兄弟你没明白我的意思

这个已经解决了 在stackoverflow上面看到的 :方法一 ie下面单独处理用 select() 这样交互一点不好
                                                                                方法二 $(this).attr('contentEditable',true)这样来处理,但是谷歌和火狐不支持,单独处理一下即可,这应该是最好的解决办法了吧
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!