-1
正如標題所說,我擁有的腳本是一個計算器,並且工作完美,但是我希望它只用於一個特定的選項,可以從一個下拉菜單。我有一個名爲EditEntry.php的頁面,您可以在其中編輯數據庫中的內容。從下拉菜單中選擇一個選項時,我希望腳本能夠運行,否則一直運行。 這是計算器腳本。當從下拉菜單中選擇一個選項時運行腳本
<script type="text/javascript">
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function KW_getVal(o){ //v1.2
var retVal="0";if (o.type=="select-one")
{retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;}
else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].value;
} else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else {
retVal=Number(o.value)}return parseFloat(retVal);
}
function KW_calcForm() { //v1.2
var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1)));
t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
if(tSp==-1) tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS;
}
function KW_calcForm() { //v1.2
var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1)));
t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
if(tSp==-1) tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS;
}
</script>
這是下拉菜單。
<td><select name="Operator">
<option value="" <?php if (!(strcmp("", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>></option>
<option value="Dani" <?php if (!(strcmp("Dani", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Dani</option>
<option value="Costi" <?php if (!(strcmp("Costi", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Costi</option>
<option value="Ioni" <?php if (!(strcmp("Ioni", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Ioni</option>
<option value="Cristina" <?php if (!(strcmp("Cristina", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Cristina</option>
<option value="Alex" <?php if (!(strcmp("Alex", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Alex</option>
<option value="Roland" <?php if (!(strcmp("Roland", htmlentities($row_Recordset1['Operator'], ENT_COMPAT, 'utf-8')))) {echo "selected=\"selected\"";} ?>>Roland</option>
</select></td>
而這正是計算器踢。
<td><input name="PretNoi" type="text" onclick="KW_calcForm('PretNoi',100,-1,'0.7','*','(','#PretFirma','-','#PretPiesa',')')" value="<?php echo htmlentities($row_Recordset1['PretNoi'], ENT_COMPAT, 'utf-8'); ?>" size="32"/></td>
我已經嘗試了很多東西,但沒有工作,我想在腳本,didint工作開始加入jQuery的選項。我嘗試添加一個「php if」,但沒有成功。我認爲在某處添加「if」選項時,只有在選擇「Roland」時計算器纔會啓動。我需要一些幫助,再次,只有在選擇「羅蘭」選項時,計算器才能工作嗎?謝謝你在前進
我試圖在腳本$的開頭加入這個( 「選擇[名稱= '操作']」)。改變(函數(){ VAR值= $(本).VAL() ; if(value ==「Roland」){SCRIPT HERE} else return false; }); ,但根本不起作用 – user5510867
你是否包含* jQuery *? – Ben
我如何包含jQuery? – user5510867