gpt4 book ai didi

javascript - 使用 Prototype 或 Javascript 选择和隐藏元素

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

有人愿意参加原型(prototype)挑战吗?我是 Prototype 的新手,我正在尝试执行以下操作。会在 jQuery 中执行此操作,但安装的唯一 js 库是 Prototype。也许有人有可行的 JavaScript 解决方案?

  1. 从表单值(前后)中去除所有空格
  2. 如果输入表单长度为 3 或更少,则隐藏所有行中的所有 checkPrice.gif 图像。

不确定使用 Prototype 是否可行。

<form method="get" id="searchForm" name="car" action="some-action">
<input type="text" value="Ford150" name="carPart" id="search" class="textContent">
</form>

<table border="1">
<tr>
<td class="description">Description:</td>
<td class="checkPrice"><p>Type:</p>
<p><a target="_blank" href="link.html"><img src="images/checkPrice.gif"></a></p>
</td>
</tr>

<tr>
<td class="description">Description:</td>
<td class="checkPrice"><p>Type:</p>
<p><a target="_blank" href="link.html"><img src="images/checkPrice.gif"></a></p>
</td>
</tr>
</table>
  • 行重复

非常感谢任何可以提供帮助的人!

最佳答案

我假设您的意思是“如果输入表单值 length 为 3 或更小”,因为默认输入值不是数字。

function updateCheckPrice(event) {
// $F() returns a string
// String.strip() trims whitespace and returns a new string
// String.length is a native property
var length = $F(this).strip().length;

// If length is 3 or less...
var action = length <= 3 ? Element.hide : Element.show;

// Pass the chosen show/hide function to every img element
$$('img[src$=checkPrice.gif]').each(action);
}

document.observe('dom:loaded', function(){
// Update as you type
Event.observe('search', 'keyup', updateCheckPrice);
});

关于javascript - 使用 Prototype 或 Javascript 选择和隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6246636/

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