js一个函数中return一个带onclick事件的链接,方法一个参数,一个this对象.
\u4e00\u4e2aonclick\u4e8b\u4ef6\u89e6\u53d1\u4e00\u4e2a\u51fd\u6570,\u5982\u4f55\u5c06\u8be5\u5143\u7d20\u7684\u5bf9\u8c61\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u4f20\u8fc7\u53bbbody div{width:60%;height:400px;margin:50px 0;border:1px solid red}//\u8868\u5355\u9a8c\u8bc1function Check(obj){if(obj.username.value == ''){alert('\u8bf7\u8f93\u5165\u8d26\u53f7');obj.username.focus();return false;}}//\u5143\u7d20\u6539\u53d8function ChangeEle(obj){if(obj.innerHTML == '\u6211\u662fdiv\u5143\u7d20'){obj.innerHTML = 'Hello World';obj.style.backgroundColor = 'red';}}\u8d26\u53f7\uff1a
\u5bc6\u7801\uff1a
\u6211\u662fdiv\u5143\u7d20 public void onShowPromptDialog1(View v){ //inflate\u9700\u8981\u663e\u793a\u5230Dialog\u91cc\u7684View\u5bf9\u8c61 LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.addfriend, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("\u8f93\u5165\u7fa4\u540d\u79f0"); builder.setIcon(R.drawable.icon); //\u4e4b\u524dinflate\u7684View \u653e\u5230dialog\u4e2d builder.setView(view); builder.setPositiveButton("\u786e\u5b9a", this); builder.setNegativeButton("\u53d6\u6d88", this); builder.create().show(); } }\u53c2\u8003\u8d44\u6599
CSDN.CSDN[\u5f15\u7528\u65f6\u95f42018-1-6]
\u70b9\u51fbfunction shanchu(a,obj){alert(a);alert($(obj).html());}\u51fd\u6570\u4f20\u5165this\u5bf9\u8c61\uff0c\u8fd9\u6837'this'\u4f1a\u88ab\u5f53\u6210\u5b57\u7b26\u4e32\u3002
绛旓細鏄笉鏄病鏈変换浣曞彉鍖栵紵锛佹墍浠ワ紝浠呬粎娣诲姞涓涓猺eturn鍏抽敭瀛楁槸娌℃湁褰卞搷鐨勩傚鏋滀簩锛氶偅濡傛灉return涓涓鏁板瓧鍛紵鍚屼笂锛岃繕鏄緭鍑簆鏌ョ湅缁撴灉锛屽鍥炬墍绀猴細鏄笉鏄湁娌℃湁浠讳綍鍙樺寲锛燂紒閭e氨鏄簡锛宺eturn鏁板瓧绫诲瀷鐨勪篃娌℃湁褰卞搷銆傚鏋滀笁锛歳eturn涓涓瓧绗︿覆 缁撴灉锛氱粨鏋滃拰娌℃湁娣诲姞return鐨勬椂鍊欐槸涓鏍风殑锛屽嵆return瀛楃涓叉槸娌...
绛旓細js return 鐨勭粨鏋滃彲浠ユ槸浠讳綍瀵硅薄 鍙互鏄竴涓暟鍊 涓涓插瓧绗 涓涓猟om 鑺傜偣 涓涓獥鍙g瓑绛 涔熷彲浠enturn 鍑芥暟鏈韩 濡 function fa(){ var fb= function(){ alert(); } return fb;}
绛旓細js涓涓嚱鏁颁腑return涓涓甯nclick浜嬩欢鐨勯摼鎺,鏂规硶涓涓弬鏁,涓涓猼his瀵硅薄. 10 瑙﹀彂鏂规硶鑾峰彇瀵硅薄鐨勫悓绾т粠鍚庡線鍓嶆暟绗笁涓璞,璁剧疆text('').鎶yntaxError:missingformalparameter閿欒... 瑙﹀彂鏂规硶鑾峰彇瀵硅薄鐨勫悓绾т粠鍚庡線鍓嶆暟绗笁涓璞,璁剧疆text('').鎶yntaxError: missing formal parameter閿欒 . 灞曞紑 鎴戞潵绛...
绛旓細鍙互杩斿洖涓涓鏁扮粍锛屽锛歠unction getArr(){ var arr=[1,2,3,4]; return arr;}var newArr=getArr();//newArr=[1,2,3,4]
绛旓細鍙互鏈変袱涓猺eturn锛屼絾鏄笉鍙互鍦ㄥ悓涓涓潡鍐呰繘琛屻備緥濡俰f锛堬級锝涳綕else锝涳綕 鍦╥f閲岄潰鍙互鏈変竴涓猺eturn锛屽湪else閲岄潰涔熷彲浠ユ湁涓涓猺eturn锛岃繖涓や釜鏄笉鍐茬獊鐨勶紝浣嗘槸濡傛灉濡備笅锛歩f(){return x;return y;}杩欎釜灏辨槸鍐茬獊鐨勪簡锛屼粬鍙墽琛岀涓涓猺eturn銆傚洜涓簉eturn鐩稿綋涓庝竴涓甫杩斿洖鍊肩殑break锛屾墽琛屼簡return涔嬪悗锛...
绛旓細鎬讳綋涓婃潵璇达紝return涓鑸槸鐢ㄥ湪鍑芥暟涓鐨勭敤鏉ュ悜瑙f瀽鍣ㄨ〃杈鹃鍑哄嚱鏁板苟杩斿洖璋冪敤鍑芥暟绌洪棿鐨勫懡浠ゃ傚湪JS杩欎釜涓撻棬鐢ㄤ簬web鐨勭▼搴忚璁¤瑷鏉ヨ锛屽叾浣跨敤鐜鏈涓哄箍娉涚殑灏辨槸鍦ㄦ祻瑙堝櫒鐜涓嬩娇鐢ㄣ俉3C瑙勫畾浜嗕竴浜涗緵JS绋嬪簭鍜岄〉闈唬鐮佽繘琛屼氦浜掔殑鎺ュ彛锛屽娴忚鍣ㄧ骇鍒殑BOM锛圔rowserObjectModel锛屾祻瑙堝櫒瀵硅薄妯″瀷锛夊拰DOM锛圖ocument ...
绛旓細鍏蜂綋璋冪敤鎯呭喌闇瑕佺湅js鏂规硶鏄庝箞鍐欑殑銆傗憼濡傛灉鏄渶绠鍗曠殑涓涓鏂规硶锛歠unctiuon dome1(){ //.浠g爜鍧梷//璋冪敤鏂规硶灏辨槸锛歞ome1()銆傗憽濡傛灉鏄棴鍖呭舰寮:function dome1(){ function dome2(){ } return function dome3(){ }}//杩欓噷鍙互璁块棶dome1鏂规硶鍐呯殑dome3鏂规硶锛宒ome2鏂规硶瀵逛笌dome1鏂规硶澶栭儴鏄笉...
绛旓細return 鏄繑鍥炵殑鎰忔, 鍦鍑芥暟閲岄潰鐨勬剰鎬濇槸褰撳墠鍑芥暟鎵ц缁撴潫浜.return 涔嬪悗鐨勮鍙ヤ笉鍐嶆墽琛屼簡. 杩斿洖缁欎笂涓涓璋冪敤瀹冪殑鍑芥暟鎴栬呰鍙.杩斿洖鍊 鍙栧喅浜庡綋鍓嶅嚱鏁板0鏄庣殑杩斿洖鍊肩被鍨. 杩斿洖鍊艰繑鍥炵粰璋冪敤璇彞.浣犳病瀛︿範杩囧熀鏈殑绋嬪簭璇彞鍚. 寤鸿浣犲厛鎵炬湰鏁欑涔 浠庡ご鍒板熬瀛︿竴涓媕ava. 鍐嶇湅js....
绛旓細涓銆佸嚱鏁拌繑鍥炲硷紝骞剁粓姝鍑芥暟鐨杩愯 璇硶锛return 琛ㄨ揪寮忥紱鍦ㄥ嚱鏁拌鍙ョ粨鏉熸椂鎵ц锛屽苟杩斿洖琛ㄨ揪寮忕殑鍊间綔涓哄嚱鏁扮殑缁撴灉锛涗簩銆佽繑鍥炴帶鍒 璇硶锛歳eturn;涓鑸潵璁诧紝涓轰簨浠跺鐞嗗嚱鏁拌繑鍥瀝eturn锛歠alse; ,浣滅敤鍦ㄤ簬闃绘榛樿浜嬩欢琛屼负鍜屽彇娑堥粯璁ゅ姩浣滐紝姣斿锛屽湪榛樿鎯呭喌涓嬬偣鍑涓涓鍏冪礌锛岄偅涔堥〉闈㈠氨浼氳烦杞埌鍏冪礌href灞炴ф寚瀹氱殑椤...
绛旓細涓や釜鍔熻兘锛1銆佽繑鍥為昏緫鍊糵alse锛2銆佺粨鏉熻繖涓鍑芥暟銆