简体   繁体   English

使用jQuery后代选择器

[英]Using Jquery Descendent Selectors

I am trying to change the background color of a textbox in a form using Jquery descendant selector on this page jQuery Descendant code 我正在尝试使用此页面上的jQuery后代选择器更改表单中文本框的背景颜色

Here's the form code I am using. 这是我正在使用的表单代码。

<form><div>Picnic Sign Up Form</div><label for="name">Full name</label>
<input name="fullname" id="fullname">
<fieldset>
<label for="firstname">Firstname here</label>
<input name="firstname" id="firstname"/> 
<label for="lastname">Lastname here</label>
<input name="lastname" id="lastname"/></fieldset></form>
$( "form fieldset input" ).css( "backgroundColor", "yellow" );

When I do this, it doesn't turn the inputs in the fieldset yellow. 当我这样做时,它不会将字段集中的输入变为黄色。 What is wrong with my code? 我的代码有什么问题?

Can't see if they've been added already by your code above but if not: 看不到上面的代码是否已经添加了它们,但是如果没有:

Scripts need to be in tags 脚本必须在标签中

Also the css for background colour is: background-color 另外背景颜色的CSS是:background-color

<script>
    $( "form fieldset input" ).css( "background-color", "yellow" );
</script>

And as you are using Jquery, you will need to include the jquery library before your script. 在使用Jquery时,您需要在脚本之前包含jquery库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM