Heim > Backend-Entwicklung > PHP-Tutorial > 大神帮我看看这段代码怎么改啊

大神帮我看看这段代码怎么改啊

WBOY
Freigeben: 2016-06-23 14:04:39
Original
977 Leute haben es durchsucht

	<div class="x_box" onmouseover="kj.addClassName(this,&#39;x_sel&#39;);" onmouseout="kj.delClassName(this,&#39;x_sel&#39;);" onclick="thisjs.cart_add({id:&#39;41&#39;,name:&#39;酸辣鸡杂&#39;,pic:&#39;/upload/attatch/2012/酸辣鸡杂饭_50_50.gif&#39;,price:&#39;13.00&#39;,type:&#39;6&#39;});">				<li class="x_tit">【酸辣鸡杂】</li>				<li class="x_intro">主料:</li>				<li class="x_pic"><img  src="./index_files/酸辣鸡杂饭.gif" alt="大神帮我看看这段代码怎么改啊" ></li>				<li class="x_tip menu_state_on"><font   style="max-width:90%">13</font>.00</li>			</div>
Nach dem Login kopieren



这是别人的,我要用smarty 输出查询到的结果,应该改哪里


回复讨论(解决方案)

首先 得把价格改了
还有图片

还有点击之后加入购物车的价格

你要在哪改代码呀,方便把要改的代码发出来吗,你发的那个代码我实在看不出在哪改。

你要在哪改代码呀,方便把要改的代码发出来吗,你发的那个代码我实在看不出在哪改。
不好意思,我的意思是原来的js 不变 改的是价格和名称(这些都是由smarty)遍历出来的


小弟初学者,对上面的html 半点不懂,所以求教。贴一下smarty的遍历

<?php include 'config.php';include 'smarty.php';$tpl->assign ("title", "欢迎访问我的订餐系统");$tpl->display("index.tpl");$sql="select * from menu";$query=mysql_query("$sql" );while(($row=mysql_fetch_array($query))==true){$menuarray[]=$row;}$tpl->assign("menu_array",$menuarray);  /*html 遍历{?section name=list loop=$menu_array?}    		{?$menu_array[list].menu_name?}       //菜名		{?$menu_array[list].price?}          //价格					{?sectionelse?}There is no orders.{?/section?}*/
Nach dem Login kopieren

哦,你发的这个代码我也有点看不懂,仔细看了下你上面的html代码:
当点击的时候,触发的是这个方法:thisjs.cart_add ,这个方法有两个参数传递,一个id,一个name,你把这个两个参数换成你要传递的两个值试一下。
由于thisjs.cart_add()代码不知道如何写的,我只能分析到这里了。

哦,你发的这个代码我也有点看不懂,仔细看了下你上面的html代码:
当点击的时候,触发的是这个方法:thisjs.cart_add ,这个方法有两个参数传递,一个id,一个name,你把这个两个参数换成你要传递的两个值试一下。
由于thisjs.cart_add()代码不知道如何写的,我只能分析到这里了。


另外一部分代码是这样子的 不是我写的,我可看不懂 是js

kj.onresize(function() {	me_resize();});kj.onload(function() {	me_resize();	kj.show("#id_cart_menu");});function me_resize(){	var h = document.documentElement.clientHeight - 32;	var l = (document.documentElement.clientWidth - 980)/2;	kj.set("#id_cart_menu" , 'style.top' , h + "px");	kj.set("#id_cart_menu" , 'style.left' , l + "px");}var thisjs = new function() {	this.mintotal = kj.toint('10');//最低起送价	this.total = 0;//合计金额	this.cart_show = 0;	this.cart_lock = false;	this.cart_add = function(o) {		var obj = kj.obj("#id_cart_box");		var obj_cart_num = kj.obj("#id_cart_num_" + o.id);		if(obj_cart_num) {			var obj_cart_price = kj.obj("#id_cart_price_" + o.id);			obj_cart_num.value = kj.toint(obj_cart_num.value) + 1;			obj_cart_price.innerHTML = "¥"+kj.toint(obj_cart_num.value) * o.price;		} else {			var obj_li=document.createElement("li");			obj_li.id = "id_cart_" + o.id;			obj_li.innerHTML = '<input type="hidden" name="cartid[]" value="'+o.id+'"><input type="hidden" name="price[]" id="id_price_'+o.id+'" value="'+o.price+'"><span class="col1">'+o.name+'</span><span class="col2">¥'+kj.toint(o.price)+'</span><span class="col3"><input type="button" name="btn_jian" value="" class="x_jian" onclick="thisjs.change_num('+o.id+',-1);"> <input type="text" name="num'+o.id+'[]" value="1" id="id_cart_num_'+o.id+'" class="x_num" onkeyup="thisjs.change_num('+o.id+')"> <input type="button" name="btn_jian" value="" class="x_jia" onclick="thisjs.change_num('+o.id+',1);"></span><span class="col4" id="id_cart_price_'+o.id+'">¥'+kj.toint(o.price)+'</span><span class="col5"><input type="button" name="btn_del" value="" class="x_del" onclick="thisjs.del('+o.id+')"></span>';			obj.appendChild(obj_li);		}		this.refresh_price();	}	//删除	this.del = function(id) {		kj.remove("#id_cart_"+id);		this.refresh_price();	}	//改变数量	this.change_num = function(id , num) {		var obj_cart_num = kj.obj("#id_cart_num_" + id);		val = kj.toint(obj_cart_num.value);		if(num) {			val+=num;			if(val<1) return;			obj_cart_num.value = val;		}		if(obj_cart_num) {			var obj_cart_price = kj.obj("#id_cart_price_" + id);			var obj_price = kj.obj("#id_price_"+id);			if(obj_cart_price) obj_cart_price.innerHTML = "¥"+val * kj.toint(obj_price.value);			this.refresh_price();		}	}	//刷新价格	this.refresh_price = function() {		var obj = kj.obj("#id_cart_box .col4");		var price = 0;		for(var i = obj.length-1 ; i >=0 ; i--) {			price += kj.toint(obj[i].innerHTML);		}		kj.set("#id_cart_menu .x_2" , 'innerHTML' , '共 <font style="font-size:14px;color:#FF821E">'+obj.length+'</font> 份,合计:');		kj.set("#id_cart_menu .x_3" , 'innerHTML' , '¥'+price);		this.total = price;		if(price == 0) {			this.showcart(0);		} else {			this.showcart(1);		}		return price;	}	//清空	this.clear = function() {		var obj = kj.obj("#id_cart_box");		obj.innerHTML = '';		this.refresh_price();	}	this.cart_init = function() {			}	//提交,保存到cookie	this.cart_submit = function() {		var obj = kj.obj("#id_cart_box li");		//检查是否已点餐		if(obj.length<1) {			alert("温馨提示:您的购物车是空的,请先点餐!");			return false;		}		//点餐价格是否达到起送价		if(this.mintotal>0 && this.total < this.mintotal) {			alert("温馨提示:由于人力成本等问题,外卖定餐需起送不得低于"+this.mintotal+"元,不便之处还请您多多包涵!");			return false;		}		var i,val,j,arr_1=[];		obj = kj.obj("#id_cart_box :cartid[]");		for(i = 0 ; i < obj.length ; i++ ) {			val = kj.toint(kj.obj("#id_cart_num_"+obj[i].value).value);			for(j=0;j<val;j++) {				arr_1[arr_1.length] = obj[i].value;			}		}		var  str_ids = "0:" + arr_1.join("|");		kj.cookie_set("cart_ids" , str_ids , 24);		window.location.href = "?app_act=cart";	}	this.mouseover = function(id) {		var obj = kj.obj("#id_nosel_"+this.orderid);		if(obj) obj.className = 'x_nosel';		kj.obj("#id_nosel_"+id).className = 'x_sel1';		this.orderid = id;		kj.addClassName("#id_li_"+id , "x_sel2");	}	this.mouseout = function(id) {		var obj = kj.obj("#id_nosel_"+this.orderid);		if(obj) obj.className = 'x_nosel';		kj.delClassName("#id_li_"+id , "x_sel2");	}	this.showcart_fixed = function(obj) {		if(obj.className == 'x_4') {			this.showcart(1);		} else {			this.showcart(0);		}	}	this.showcart = function(show) {		if(this.cart_lock) return;		if(this.cart_show == show) return;		this.cart_show = show;		var h = document.documentElement.clientHeight - 32;		var obj = kj.obj("#id_cart_menu");		var offset = kj.offset(obj);		var top = offset.top;		this.cart_lock = true;		if(show) {			kj.set("#id_cart_menu .x_top .x_4" , 'className' , 'x_6');			this.showcart_time('#id_cart_menu' , top , h-120 , -10);		} else {			kj.set("#id_cart_menu .x_top .x_6" , 'className' , 'x_4');			this.showcart_time('#id_cart_menu' , top , h , 10);		}	}	this.showcart_time = function(id , top , top_target , val) {		var obj = kj.obj(id);		var x = top -  top_target;		if(val > 0) x = x * -1;		if( x > 0 ) {			kj.set(obj, 'style.top' , top+'px');			top+=val;			window.setTimeout("thisjs.showcart_time('" + id + "'," + top + "," + top_target + "," + val + ")", 20);   		} else {			kj.set(obj, 'style.top' , top_target+'px');			this.cart_lock = false;		}	}}kj.onload(function(){	thisjs.cart_init();});
Nach dem Login kopieren

onmouseout="kj.delClassName(this,&#39;x_sel&#39;);" onclick="thisjs.cart_add({id:&#39;41&#39;,name:&#39;酸辣鸡杂&#39;,pic:&#39;/upload/attatch/2012/酸辣鸡杂饭_50_50.gif&#39;,price:&#39;13.00&#39;,type:&#39;6&#39;});
Nach dem Login kopieren


传的这个值 里面的:'6'    是什么意思 

传值传到哪去了呢

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage