亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

?函數采用如下實現方式,請問該如何實現需要的效果?

?函數采用如下實現方式,請問該如何實現需要的效果?

藍山帝景 2022-11-04 14:10:46
function $(id) {return document.getElementById(id);}function hide(){$(id).style.display='none';}如何實現$("id").hide()方式使用<div id="box"></div>function show(){$(id).style.display='block';}function html(str){$(id).innerHTML=str;}如何實現類似jQuery的使用方式:使用$("box")返回document.getElementById(“box”)對象,使用$("box").show()顯示元素,使用$("box").hide()隱藏元素,使用$("box").html("hello")設置內容
查看完整描述

2 回答

?
鴻蒙傳說

TA貢獻1865條經驗 獲得超7個贊


<!DOCTYPE HTML><html><head><meta charset=UTF-8><title>recursion</title><style type="text/css"></style><script type="text/javascript">    function $ (id)    {        return document.getElementById (id);    };    $.prototype = Element.prototype;    $.prototype.constructor = $;    $.prototype.hide = function ()    {        this.style.display = 'none';        return this;    };    $.prototype.show = function ()    {        this.style.display = 'block';        return this;    };    $.prototype.html = function (str)    {        this.innerHTML = str;        return this;    };    onload = function ()    {        $ ('box').html ("spider man").hide ().show ();    }</script></head><body>    <div id="box"></div></body></html>




查看完整回答
反對 回復 2022-11-08
?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊


function $(id) {         this.hide = function(){         document.getElementById(id).style.display='none';     };           this.show = function() {         document.getElementById(id).style.display='block';     };           this.html = function(str){                  document.getElementById(id).innerHTML=str;     }}

要實現的功能,就要使用面向對象編程,上面的例子很簡單,只是實現你問題中最簡單的三個方法,讓你了解下思想

如果要實現Jquery的大致功能,結構會較復雜,估計一下子吸收不了,慢慢來吧


查看完整回答
反對 回復 2022-11-08
  • 2 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號