Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery中的end()方法可以工作,但表现出奇怪的行为_Jquery - Fatal编程技术网

jquery中的end()方法可以工作,但表现出奇怪的行为

jquery中的end()方法可以工作,但表现出奇怪的行为,jquery,Jquery,下面是HTML代码 <div id="Parent"> This is Parent Div <p> This is first child.</p> <p> This is second child.</p> <p> This is Third child.</p> </div>

下面是HTML代码

<div id="Parent">
            This is Parent Div
             <p> This is first child.</p>
             <p> This is second child.</p>
             <p> This is Third child.</p>
        </div>

<input type="button" id="clickme" value ="click me" />
在上面的jquery代码中,我尝试将不同的样式应用于子级和父级。除了斜体风格外,一切都很好。谁能解释一下为什么会发生这种奇怪的事情


抱歉错过了这一点-我正在应用斜体字的家长,但孩子们也得到了改变。如何防止这种情况?

在父级和子级之间来回跳转以设置不同的css没有什么意义

只需将父级的css属性和子级的css属性组合起来,并且只为每个子级调用一个css。它消除了使用
end()

$('#clickme').click(function() {
    $('#Parent')   
    .css({
        'font-style': 'italic',
        'color': 'red',
        'border-color': 'blue',
        'border-width': '3px',
        'border-style': 'solid'
    })
   .children()
   .css({
       'color':'blue',
        'border-color': 'red',
        'border-width': '2px',
        'border-style': 'solid'
    })
});
演示:


我怀疑您只希望父级中的文本使用斜体,在这种情况下,现在很明显您也需要将子级设置为普通字体。

嘿,您希望出现什么样的行为?如果你打算将整个
变成斜体,那么它对我来说很好:。我测试了fIREFOX IE并将其转换为斜体,就像是的,这就是我想要的。如果我需要将子项设置为非斜体状态,那么这将取消end()函数的用途。请纠正我对end()函数的理解有误。
$('#clickme').click(function() {
    $('#Parent')   
    .css({
        'font-style': 'italic',
        'color': 'red',
        'border-color': 'blue',
        'border-width': '3px',
        'border-style': 'solid'
    })
   .children()
   .css({
       'color':'blue',
        'border-color': 'red',
        'border-width': '2px',
        'border-style': 'solid'
    })
});