带有附加选择器的 jQuery DOM 节点
在 jQuery 中传入 DOM 节点后,我尝试进行其他选择。在此示例中,我尝试在选择框中进行更改后显示一个“隐藏”提交按钮(注意,我传递的是 FORM 元素,而不是 SELECT 元素:
<form id="UpdateRegistrationStatusForm">
<select id="registration_status" onchange="AdjustRegistrationStatus(this.form)">
<option value="1">approved</option>
<option value="2">cancelled</option>
</select>
<input id="registration_status_update" type="submit" style="display:none" value="update"/>
</form>
因此,我传递的 jQuery 代码想做,但不起作用看起来像这样...
function AdjustRegistrationStatus(myForm)
{
jQuery(myForm "#registration_status_update").show();
if (jQuery(myForm "#registration_status").val() == 1)
{
//do some other things here...
}
}
我想从 FORM DOM 对象开始并添加额外的“字符串”选择器,有什么帮助吗?
I'm trying to do additional selections after I pass in a DOM node in jQuery. In this example, I'm trying to show a "hidden" submit button after a change in the select box (notice, I'm passing in the FORM element, NOT the SELECT element:
<form id="UpdateRegistrationStatusForm">
<select id="registration_status" onchange="AdjustRegistrationStatus(this.form)">
<option value="1">approved</option>
<option value="2">cancelled</option>
</select>
<input id="registration_status_update" type="submit" style="display:none" value="update"/>
</form>
So, the jQuery code that I WANT TO DO, BUT DOESN'T WORK looks something like this...
function AdjustRegistrationStatus(myForm)
{
jQuery(myForm "#registration_status_update").show();
if (jQuery(myForm "#registration_status").val() == 1)
{
//do some other things here...
}
}
I want to start with a FORM DOM object and add additional "string" selectors. Any help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您正在寻找
find
函数,但我有点困惑,因为从属元素有 ID,所以您实际上不需要从表单开始。如果他们有其他一些非唯一的东西(比如一个类),你可能会这样做:..但是对于 ID 来说,没有太多理由这样做。
I suspect you're looking for the
find
function, but I'm a bit confused because the subordinate elements have IDs, so you don't really need to start with the form. If they had some other, non-unique thing (like a class) you might do this:..but with IDs there's not much reason to.
为此,请使用
#id
选择器(id
应该是唯一的,无论它相对于什么):在其他情况中,使用
.find()
像这样:.find()
查找与选择器匹配的所有后代,它是用于移动的众多树遍历函数之一。For this, use an
#id
selector (anid
should be unique, doesn't matter what it's relative to):In other cases, use
.find()
like this:.find()
finds all descendants matching the selector, it's one of many tree traversal functions used for moving around.