大佬教程收集整理的这篇文章主要介绍了javascript – jQuery $(this).attr(“id”)不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是代码:
function showHideOther(obj){ var sel = obj.options[obj.SELEctedIndex].value; var ID = $(this).attr("id"); alert(ID); if(sel=='other'){ $(this).html("<input type='text' name='" + ID + "' id='" + ID + "' />"); }else{ $(this).css({'display' : 'none'}); } }
HTML:
<span class='left'><label for='race'>Race: </label></span> <span class='right'><SELEct name='race' id='race' onchange='showHideOther(this);'> <option>SELEct one</option> <option>one</option> <option>two</option> <option>three</option> <option value="other">Other</option> </SELEct> </span>
这可能是我没有注意到的小事情,我做错了什么?
Thanx提前!
此外,创建一个jQuery对象和使用它的attr()方法来获取元素ID是低效和不必要的.只需使用元素的id属性,该属性适用于所有浏览器.
function showHideOther(obj){ var sel = obj.options[obj.SELEctedIndex].value; var ID = obj.id; if (sel == 'other') { $(obj).html("<input type='text' name='" + ID + "' id='" + ID + "' />"); } else { $(obj).css({'display' : 'none'}); } }
以上是大佬教程为你收集整理的javascript – jQuery $(this).attr(“id”)不起作用全部内容,希望文章能够帮你解决javascript – jQuery $(this).attr(“id”)不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。