Javascript 检查span类内容,然后使用jquery更新数量?
我这里有代码:Javascript 检查span类内容,然后使用jquery更新数量?,javascript,jquery,Javascript,Jquery,我这里有代码: //Check current if (parseInt($("#Quantity").val()) < 25) { // If it is less than 25 then set it to 25 $("#Quantity").attr("value", "25"); } //检查当前 if(parseInt($(“#数量”).val())
//Check current
if (parseInt($("#Quantity").val()) < 25) {
// If it is less than 25 then set it to 25
$("#Quantity").attr("value", "25");
}
//检查当前
if(parseInt($(“#数量”).val())<25){
//如果小于25,则将其设置为25
美元(“数量”).attr(“价值”、“25”);
}
它检查数量框是否小于25,如果小于25,则向框中添加25。
问题出在某个特定产品上,我需要检查我的页面是否包含:
<span class="ProductNameText">This is product ABC</span>
这是ABC产品
这是一个解决办法,因为客户只有2种产品,不需要25个数量。理想情况下,我希望检查页面是否包含Kit Option表单字段,然后在框中添加25个字段
关于如何检查跨度,然后更新数量的任何想法。但是数量不应该强制,因此如果用户想要6个项目,他们应该能够添加该数字。尝试使用
长度
:
//Check current
if ($("#Quantity").val().length < 25) {
// If it is less than 25 then set it to 25
$("#Quantity").attr("value", "25");
}
//检查当前
如果($(“#数量”).val().length<25){
//如果小于25,则将其设置为25
美元(“数量”).attr(“价值”、“25”);
}
如果您只想检查是否存在类为“ProductNameText”的范围,可以执行以下操作-
if (parseInt($("#Quantity").val()) < 25) && ($("span.ProductNameText").length > 0) {
// If it is less than 25 then set it to 25
$("#Quantity").attr("value", "25");
}
这将检查文本框的值一旦文本框失去焦点,可以根据span是否存在来切换逻辑($('span.ProductNameText')。text()='This is product ABC'){
if($('span.ProductNameText').text()=='This is product ABC'){
//Check current
if (parseInt($("#Quantity").val()) < 25) {
// If it is less than 25 then set it to 25
$("#Quantity").attr("value", "25");
}
}
//检查电流
if(parseInt($(“#Quantity”).val())<25{
//如果小于25,则将其设置为25
美元(“数量”).attr(“价值”、“25”);
}
}
希望我理解您的查询。谢谢,但这如何解决从span类中查找产品名称的问题?如果它包含“某物”,则用户可以选择1-2000谢谢,如果我找到span文本,我需要能够在框中插入小于25和大于25的值。用户应该能够做到这一点。。。
$("#Quantity").change( function() {
if ($("span.ProductNameText:contains('sometext')").length > 0) {
// check input ($(this).val()) here
}
else // check for differnt input ($(this).val()) here wher span doe snot exist
});
if($('span.ProductNameText').text()=='This is product ABC'){
//Check current
if (parseInt($("#Quantity").val()) < 25) {
// If it is less than 25 then set it to 25
$("#Quantity").attr("value", "25");
}
}