php - <button> Same Button, Multiple Locations, Different Code -
i writing application in jqtouch, , using big red button
<a href="#" class="redbutton">red</a>
i using php dynamically build jqt page multiple divs. app server management console gets data mysql. idea use while loop make div each server returned in mysql query, , each div have delete server button(the big red button). have call dame bit of code because of whole dynamic page generating thing. wondering if there way have onclick function call button red know div button in calling function. there button in multiple divs call same code, have know server delete. suggestions?
here full source code.
<html> <link rel="stylesheet" href="jq_touch/themes/css/jqtouch.css" title="jqtouch"> <script src="jq_touch/src/lib/zepto.min.js" type="text/javascript" charset="utf-8"></script> <script src="jq_touch/src/jqtouch.min.js" type="text/javascript" charset="utf-8"></script> <!-- uncomment following 2 lines (and comment out previous two) use jquery instead of zepto. --> <!-- <script src="../../src/lib/jquery-1.7.min.js" type="application/x-javascript" charset="utf-8"></script> --> <!-- <script src="../../src/jqtouch-jquery.min.js" type="application/x-javascript" charset="utf-8"></script> --> <script src="../../extensions/jqt.themeswitcher.min.js" type="application/x-javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var jqt = new $.jqtouch({ icon: 'jqtouch.png', icon4: 'jqtouch4.png', addglosstoicon: false, startupscreen: 'jqt_startup.png', statusbar: 'black-translucent', themeselectionselector: '#jqt #themes ul', preloadimages: [] }); // sample javascript functions: $(function(){ // show swipe event on swipe test $('#swipeme').swipe(function(evt, data) { var details = !data ? '': '<strong>' + data.direction + '/' + data.deltax +':' + data.deltay + '</strong>!'; $(this).html('you swiped ' + details ); $(this).parent().after('<li>swiped!</li>') }); $('#tapme').tap(function(){ $(this).parent().after('<li>tapped!</li>') }); $('a[target="_blank"]').bind('click', function() { if (confirm('this link opens in new window.')) { return true; } else { return false; } }); // page animation callback events $('#pageevents'). bind('pageanimationstart', function(e, info){ $(this).find('.info').append('started animating ' + info.direction + '… , link ' + 'had custom data: ' + $(this).data('referrer').data('custom') + '<br>'); }). bind('pageanimationend', function(e, info){ $(this).find('.info').append('finished animating ' + info.direction + '.<br><br>'); }); // page animations end ajax callback event, example 1 (load remote html first time) $('#callback').bind('pageanimationend', function(e, info){ // make sure data hasn't been loaded (we'll set 'loaded' true couple lines further down) if (!$(this).data('loaded')) { // append placeholder in case remote html takes sweet time making // then, overwrite "loading" placeholder text remote html $(this).append($('<div>loading</div>').load('ajax.html .info', function() { // set 'loaded' var true know not reload // html next time #callback div animation ends $(this).parent().data('loaded', true); })); } }); // orientation callback event $('#jqt').bind('turn', function(e, data){ $('#orient').html('orientation: ' + data.orientation); }); }); </script><?php //connect mysql_connect("localhost", "root", "root") or die(mysql_error()); //make , store queries mysql_select_db("servermgr") or die(mysql_error()); $result = mysql_query("select * servers") or die(mysql_error()); //echo constant html echo'<div id="serverset">'; echo'<div class="toolbar">'; echo'<h1>servers home</h1> '; echo'</div>'; echo'<ul class="rounded">'; //begin printing out mysql rows (list items) while($row = mysql_fetch_array( $result )) { //$row_friendlyname = $_row['friendly_name'] $friendlyname_nospaces = str_replace(' ', '_', $row[friendly_name]); echo'<li class=""><a href="#'.$friendlyname_nospaces.'">'.$row["friendly_name"].'</a></li>'; } //close list echo'</ul>'; echo '</div>'; //redo previous queries print out divs mysql_select_db("servermgr") or die(mysql_error()); $result2 = mysql_query("select * servers") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $friendlyname_nospaces2 = str_replace(' ', '_', $row2[friendly_name]); echo '<div id="'.$friendlyname_nospaces2.'">'; echo'<div class="toolbar">'; echo'<h1>'.$row2[friendly_name].'</h1> '; echo '<a href="#" class="back">back</a>'; echo'</div>'; echo'<ul class="rounded">'; echo '<li>friendly name: '.$row2[friendly_name].'</li>'; echo '<li>ip address: '.$row2[ip].'</li>'; echo '<li>server hostname: '.$row2[hostname].'</li>'; echo '<li>mac address: '.$row2[mac].'</li>'; echo'</ul>'; echo'<button href="#" class="redbutton">red</button>'; echo'</div>'; } //end of php ?> </body> </html>
add data attribute "big red button" follows
<a href="#" class="redbutton" data-server="serverval">red</a>
and handling code retrieve data value follows
var server = $(this).attr('data-server');
then can condition logic.
Comments
Post a Comment