当我点击".pushme"按钮时,它将其文本变为"不要逼我".当再次点击按钮时,我想再次将文本转为"推我".我怎样才能做到这一点?
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button class='pushme'>PUSH ME</button>
<script>
$(".pushme").click(function () {
$(this).text("DON'T PUSH ME");
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用nextUntil方法来获取两个元素之间的所有东西.但是这种方法不包括text nodes输出.它给出了一个像数组[<br>, <br>, <br>].我如何获得包括文本节点在内的所有内容?谢谢.
这是html代码:
$('.content a:contains("spoiler").b:even').each(function() {
$(this).nextUntil('.content a:contains("spoiler").b')
.wrapAll('<div style="border:solid 1px black;"></div>');
});Run Code Online (Sandbox Code Playgroud)
这是我愚蠢的js代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content">
--- <a class="b" href="/?q=spoiler">spoiler</a> ---
<br>
<br> dangerous text here
<br> --- <a class="b" href="/?q=spoiler">spoiler</a> ---
<br> safe text here
<br> --- <a class="b" href="/?q=spoiler">spoiler</a> ---
<br>
<br> dangerous text here
<br> --- <a class="b" href="/?q=spoiler">spoiler</a> ---
</div>Run Code Online (Sandbox Code Playgroud)
jsfiddle:http://jsfiddle.net/Lwk97rvq/1/
我正在尝试改变div的宽度.但$(div#i)不是真的.我怎样才能做到这一点?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
var things = new Array();
things[0] = 13; things[1] = 26; things[2] = 39;
for(var i=0;i<things.length;i++)
$(div#i).css("width",things[i]*100);
</script>
</head>
<body>
<div id="0" style=" width: 300px; height:20px; margin-left: 25px; padding-left: 15px; background-color: #900"> </div> <br>
<div id="1" style=" width: 300px; height:20px; margin-left: 25px; padding-left: 15px; background-color: #900"> </div> <br>
<div id="2" style=" width: 300px; height:20px; margin-left: 25px; padding-left: 15px; background-color: #900"> </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)