看板 Web_Design 關於我們 聯絡資訊
小弟做了一個網頁包含了四個超連結 網頁:index.php 超連結1:index.php?page=A 超連結2:index.php?page=B 超連結3:index.php?page=C 超連結4:index.php?page=D 進入首頁(index.php),點超連結後(index.php?page=A), 網頁的jquery語法會失效,但按了重新更新後jquery又有效了 PS:我有用樣板引擎smarty 麻煩各位高手給小弟指點迷津或給個方向 這問題困擾好幾天了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.35.130.39 ※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1423640989.A.671.html
oToToT: 看不太懂.... 02/11 15:59
onininon: jquery語法會失效 有錯誤訊息嗎 02/11 16:05
MangoTW: 什麼語法…講清楚一點… 02/12 00:52
aspdoctor: 你用到Ajax? 是的話有變動的元素event要重新bind 02/12 02:59
以下是我的程式碼 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>HomeGatWay</title> <link rel="shortcut icon" href="ext/favicon.ico"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,700"> <link rel="stylesheet" href="ext/css/themes/default/jquery.mobile-1.4.5.min.css"> <link rel="stylesheet" href="templates/style/default.css"> <script src="js/jquery.js"></script> <script src="js/jquery.mobile-1.4.5.js"></script> </head> <body> <div data-role="page"> <div data-role="header" data-position="fixed" data-tap-toggle="false"> <a href="#nav-panel" class="jqm-navmenu-link ui-nodisc-icon ui-alt-icon ui-btn-left ui-btn ui-icon-bars ui-btn-icon-notext ui-corner-all" data-role="button" role="button">Menu</a> <h1><div class="top_user" style="float:right">page_main</div></h1> </div><!-- /header --> <div role="main" class="ui-content"> <div class="actionbar"> <div style="float:right;"> <nav> <a href="?page=roon&action=append">p1</a> <a href="?page=roon&action=edit&roonno=">p2</a> <a href="?page=roon&action=cancel&roonno=">p3</a> <a href="?page=roon&action=delete&roonno=">p4</a> </nav> </div> </div> </div><!-- /content --> <script> $(function(){alert('456');}); </script> </div><!-- /page --> </body> </html> 我用ie/chrome 測過 點P1~P4的超連結 都會有一個超連結點下去後alert('456');會執行不到 按F5重新更新後就會正常跳出alert('456'); 最後發現只要把 <script src="js/jquery.mobile-1.4.5.js"></script>這段拿掉就 正常了 ※ 編輯: e2755699 (114.35.130.39), 02/12/2015 11:26:02
cokellen: 在<a>加上data-ajax="false" 試看看 02/12 11:57
cokellen: jquery mobile官方文件有說明Link的使用 02/12 11:58
e2755699: 挖~好像有效耶 我找了超久 02/12 13:08