Prototype有没有像jQuery这样的冲突选项吗? [英] Does Prototype has a no conflict option like jQuery?
问题描述
我已经尝试了谷歌搜索,但它只提出了jQuery noconflict选项。
I have tried Googling this but it only ever comes up with the jQuery noconflict option.
我会使用这个,但我的网站非常jQuery,它将需要非常白,以及我添加的原型代码可能是暂时的,只有几行。
I would use this but my site is very jQuery heavy and it will take quite a white, as well as this the prototype code I'm adding may be temporary and is only a few lines.
如果没有原型没有冲突选项怎么样我转换下面的代码,我的javascript代码是有限的?
If there is no prototype no conflict option how would I convert the below code, my javascript codes are limited?
// JavaScript Document
// calculate price based on quantity
function changeQty(change){
var currentQty = parseInt($F('quant')) // Where quant is the id of your quantity input field. Gets value of currentQty field
switch (change) {
case 'add':
currentQty += 1
$('quant').value = currentQty
calculate()
break
case 'subtract':
if (currentQty > 1) { // only subtract if qty is greater than zero
currentQty -= 1
$('quant').value = currentQty
calculate()
}
break
case 'field':
if (currentQty > 0) {
window.setTimeout('calculate()', 500)
}
break
}
}
function calculate(){
var currentQty = parseInt($F('quant')) // Where quant is the id of your quantity input field. Gets value of currentQty field
var jsnormalprice = $F('jsnormalprice') // Where jsnormalprice is the id of your hidden base price field. Gets value of base_price field
var jsspecialprice = $F('jsspecialprice') // Where is the id of your hidden base price field. Gets value of base_price field
if (currentQty > 0) { // Don't want price to display if zero if customer zeros out quantity
var new_jsnormalprice = jsnormalprice * currentQty // Calculate the price.
var new_jsnormalprice = new_jsnormalprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
var new_jsspecialprice = jsspecialprice * currentQty // Calculate the price.
var new_jsspecialprice = new_jsspecialprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
} else { // set price back to original price
new_jsnormalprice = jsnormalprice
new_jsspecialprice = jsspecialprice
}
$('jsnormalpriceshow').update(new_jsnormalprice) // Where jsnormalpriceshow is the id of your span for the echoed product price
$('jsspecialpriceshow').update(new_jsspecialprice) // Where jsspecialpriceshow is the id of your span for the echoed product price
}
推荐答案
Prototype没有没有冲突模式..
Prototype does not have a no conflict mode..
我已经转换了你的代码,但我可能错过了一两个地方..
I've converted your code, but I may have missed a spot or two..
一般来说, $('elemID')
=> $('#elemID')
和 $ F('elemID')
=> $('#elemID')。val()
是什么我已经完成..
Generally, $('elemID')
=> $('#elemID')
and $F('elemID')
=> $('#elemID').val()
is what I've done..
// JavaScript Document
// calculate price based on quantity
function changeQty(change){
var currentQty = parseInt($('#quant').val()) // Where quant is the id of your quantity input field. Gets value of currentQty field
switch (change) {
case 'add':
currentQty += 1
$('#quant').val(currentQty)
calculate()
break
case 'subtract':
if (currentQty > 1) { // only subtract if qty is greater than zero
currentQty -= 1
$('#quant').val(currentQty)
calculate()
}
break
case 'field':
if (currentQty > 0) {
window.setTimeout('calculate()', 500)
}
break
}
}
function calculate(){
var currentQty = parseInt($('#quant').val()) // Where quant is the id of your quantity input field. Gets value of currentQty field
var jsnormalprice = $('#jsnormalprice').val() // Where jsnormalprice is the id of your hidden base price field. Gets value of base_price field
var jsspecialprice = $('#jsspecialprice').val() // Where is the id of your hidden base price field. Gets value of base_price field
if (currentQty > 0) { // Don't want price to display if zero if customer zeros out quantity
var new_jsnormalprice = jsnormalprice * currentQty // Calculate the price.
var new_jsnormalprice = new_jsnormalprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
var new_jsspecialprice = jsspecialprice * currentQty // Calculate the price.
var new_jsspecialprice = new_jsspecialprice.toFixed(2) // Only allow 2 decimals. I'll let you add rounding features up or down.
} else { // set price back to original price
new_jsnormalprice = jsnormalprice
new_jsspecialprice = jsspecialprice
}
$('#jsnormalpriceshow').html(new_jsnormalprice) // Where jsnormalpriceshow is the id of your span for the echoed product price
$('#jsspecialpriceshow').html(new_jsspecialprice) // Where jsspecialpriceshow is the id of your span for the echoed product price
}
这篇关于Prototype有没有像jQuery这样的冲突选项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!