0 0

prototype的show方法5

如果原来的值是display:none,执行show就没反应,看了一下代码,好象show只是把display赋成空串,css手册查了一下,并没有说明display赋成空串是什么情况


下面是测试代码 



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ru">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html;charset=gbk">
    
    <style type="text/css">
    #info{
    background:orange;
    width:200px;
    display:none;
    margin:0 auto;
    
    }
    
    </style>
    <script type="text/javascript" src="../prototype.js"></script>
</head>
<body>
	
 <dir id="info"   >aaa</dir>
	
	<button id="btn">test</button>
	
	<script type="text/javascript">
	
	$("btn").observe("click",function(ev){
 
 	$('info').show(); 
	});
	
	</script>
</body>
</html>


问题补充:
wzglovejava 写道
$('info').show(); 修改成$('info').style.display='block';


这样写用mt的意义在什么地方?
直接用js不就行了吗

问题补充:
jsntghf 写道
$('info').style.display='block';或者$('info').style.display='';都行

建议用后者,前者某些情况下会有问题。


什么情况,能举例说明下吗
2011年5月02日 03:57

3个答案 按时间排序 按投票排序

0 0

采纳的答案

为你这个问题重新下了个prototype,很久没用了(07年后就没使用了)。
$("btn").observe("click",function(ev){ 
  
    $('info').show();  
    }); 
     
需要改成如下代码:
$("btn").on("click", function (ev) {
   Element.show("info");
});
元素的show方法是需要通过Element来使用的,show中可以带多个参数。
即使这样子修改了这里还是无法显示出来,原因在于css样式级别的覆盖问题,其实次要说一点,目前prototype库对show的实现是$(element).style.display="";这样子来处理的,所以一定程度上直接调用Element.show("info")不一定能显示出来,此时建议你修改成$("info").style.display="block";来显示.

2011年5月10日 00:17
0 0

$('info').style.display='block';或者$('info').style.display='';都行

建议用后者,前者某些情况下会有问题。

2011年5月04日 10:53
0 0

$('info').show(); 修改成$('info').style.display='block';

2011年5月03日 11:12

相关推荐

    js使用原型对象(prototype)需要注意的地方

    我们先来一个简单的构造函数+原型对象的... CreateObj.prototype.showUserName = function () { return this.userName; } CreateObj.prototype.showUserAge = function () { return this.userAge; } 这个程序,没

    Prototype使用指南之ajax

    Prototype中的ajax.js提供了一个非常好用的ajax框架,一般应用中简单的调用以下代码就可以了 new Ajax.Request( url, {method: “get”, onSuccess: showFilter, onFailure: function(request){alert&#40;”...

    [js高手之路]图解javascript的原型(prototype)对象,原型链实例

    我们通过原型方式,解决了多个实例的方法共享问题,接下来,我们就来搞清楚原型(prototype),原型链的来龙去脉。 function CreateObj(uName) { this.userName = uName; } CreateObj.prototype.showUserName = ...

    prototype Element学习笔记(Element篇三)

    一、筛选类函数 ancestors、recursivelyCollect... 二、增、删、改元素类函数 insert、update、remove、replace、wrap、cleanWhitespace 三、设置元素各种属性类函数 visible、toggle、hidde、show、identify、readAttr

    yuv_show.zip_YUV_player

    Prototype of YUV player in opencv

    prototype Element学习笔记(篇一)

    从而获得扩展后的element对象,然后,我们就可以用它的各种扩展出来的方法了,如: $(‘div1’).addClassName(‘loading’).show(); 所以,我们研究Element的扩展正应当以此为入口。 function $(element) { if ...

    基础的prototype.js常用函数及其用法

    prototype.js 常用函数 : Element.toggle 交替隐藏或显示 Element.toggle(”div1”,”div2”) Element.hide 隐藏 Element.hide(”div1”,”div2”) Element.show 显示 Element.show(”div1”,”div2”) ...

    原生js仿jquery一些常用方法(必看篇)

    最近迷上了原生js,能不用jquery等框架的情况都会手写一些js方法,记得刚接触前端的时候...Object.prototype.show = function(){ this.style.display="block"; return this; } return this的好处在于链式调用。 2

    prototype.js常用函数详解

     Element.show(”div1”,”div2”)  Element.remove  删除  Element.remove(”div1”,”div2”)  Element.getHeight  取得高度  Element.getHeight(”div1”)  Toggle.display  和Elemen

    JavaScript中prototype为对象添加属性的误区介绍

    MenuControl.prototype.show = function(){ if(pointControl.boxDisplay){ pointControl.hide(); } menuBoxDiv.style.display = “”; this.boxDisplay = true; this.controlUI.style.backgroundColor =

    ajax回调函数参数传递正确方法

    ClassX.prototype.show = function (param) { alert&#40;this.name + ” ” + param&#41;; }; } var o = new ClassX(“name”); o.show(“param”);//name param 但是,上面是虽然是直接在函数签名中定义了参考,...

    Javascript中prototype的使用详解

    先看下面一段代码: function Machine(ecode, horsepower) { this.ecode = ecode; this.horsepower = horsepower; } function showme() { alert&#40;...machine.showme = showme; machine.showme();

    jquery插件使用方法大全

     代码 $("#msg").show("fast"); $("#msg").hide("slow"); $("#msg").fadeIn(); $("#msg").fadeOut(); 没错,上面两行代码已经分别实现了一个id为Msg的jquery对象的渐入和淡出。做一个像Gmail一样的动态加载通知条,...

    jQuery链式调用与show知识浅析

    上篇文章给大家介绍了jQuery的框架,有关jquery的基础知识可以参考下。...return new jQuery.prototype.init(sel); } jQuery.prototype = { constructor: jQuery, init: function(sel){ if(typeof sel === 'str

    Android代码-mirror

    This is the source code for the prototype UI of my smart mirror project outlined in this article. Simply import the whole project into Android Studio, then build and run the apk. While the time, date...

    A simplified protocol for energy self-sufficient sensors in an IEEE 802.15.4 ZigBee WSN.pdf

    (mains- or battery powered) routers and show actual measurement results and calculated values to indicate the improvements of this adapted hybrid topology. Index Terms—IEEE 802.15.4, industrial ...

    详解JavaScript基于面向对象之继承实例

    javascript面向对象继承的简单实例: 作为一门面向对象的语言,继承自然是它的一大特性,尽管javascript的面向对象的实现机制和和c#和java这样... parent.prototype.show = function(){ alert&#40;'父级方法'&#41;;

    最完整最全面的网站开发帮助文档,开发网站必不可少的工具书

    18.prototype.chm 19.SQL参考手册.chm 20.XMLDOM对象手册.chm 21.XMLHTTP 手册.CHM 22.xmlHttp对象参考.chm 23.设计模式手册.chm 24.网页设计配色常识.chm 25.正则表达式系统教程.CHM 26.SQL语言参考大全(CHM版)2.1M...

    A New Parallel Processing ups with performance of harmonic suppression and reactive power compensation.pdf

    A new current-mode voltage-source parallel ...prototype is developed and tested to verify its performance. The test results show that the proposed UPS has the expected performance .

    Pro Python System Administration(Apress,2ed,2014)

    It will show you how to approach and resolve real-world issues that most system administrators will come across in their careers. This book has been updated using Python 2.7 and Python 3 where ...

Global site tag (gtag.js) - Google Analytics