gpt4 book ai didi

jquery - 样式的表单输入条件

转载 作者:行者123 更新时间:2023-11-28 11:07:12 25 4
gpt4 key购买 nike

我有这个 jquery

$(function(){
function validatemin() {
if (('input[name=amount]').value() <= 2.00) {
$('#inpamount').css('color', 'red');
}
else {
}
}
});

应该在下面的 HTML 中触发 onkeyup,改变输入文本的颜色。

<input id='inpamount' type="text" name="amount" value="2.00" onkeyup="validatemin()">

将文本变成红色。任何想法为什么它不起作用?

此外,我如何更改 if 以便 if input > 2.00 (就像现在一样)OR < VALUE OF ANOTHER ELEMENT .例如,另一个元素的类是 otherelement

干杯

最佳答案

    未看到
  1. validatemin,因为它在 ready 处理程序的范围内。提取出来
  2. 要在 jQuery 中获取值,请使用 val(),而不是 value()
  3. 在启动选择器之前,您需要 jQuery 对象或别名 $

function validatemin() {
if ($('input[name=amount]').val() <= 2.00) {
$('#inpamount').css('color', 'red');
} else {
$('#inpamount').css('color', '');
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<input id='inpamount' type="text" name="amount" value="2.00" onkeyup="validatemin()">

更新

Also, how can I change the if so that if input > 2.00 (as it is now) OR < VALUE OF ANOTHER ELEMENT. For example the class of the other element is otherelement

if条件改为

if ($('input[name=amount]').val() <= 2.00 || $('.otherelement').val() <= 2.00) 

关于jquery - 样式的表单输入条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31014298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com